Skip to content

Commit

Permalink
Add support for VCF (and fix ICS detection) (#451)
Browse files Browse the repository at this point in the history
Co-authored-by: Borewit <[email protected]>
  • Loading branch information
mdartic and Borewit authored May 5, 2021
1 parent 6ab25f3 commit 29618c8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
4 changes: 3 additions & 1 deletion core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ declare namespace core {
| 'stl'
| 'chm'
| '3mf'
| 'zst';
| 'zst'
| 'vcf';

type MimeType =
| 'image/jpeg'
Expand Down Expand Up @@ -240,6 +241,7 @@ declare namespace core {
| 'application/dicom'
| 'audio/x-musepack'
| 'text/calendar'
| 'text/vcard'
| 'model/gltf-binary'
| 'application/vnd.tcpdump.pcap'
| 'audio/x-dsf' // Non-standard
Expand Down
25 changes: 18 additions & 7 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,13 +911,6 @@ async function _fromTokenizer(tokenizer) {
};
}

if (checkString('BEGIN:')) {
return {
ext: 'ics',
mime: 'text/calendar'
};
}

if (check([0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C])) {
return {
ext: '7z',
Expand Down Expand Up @@ -1213,6 +1206,24 @@ async function _fromTokenizer(tokenizer) {
// Increase sample size from 12 to 256.
await tokenizer.peekBuffer(buffer, {length: Math.min(256, tokenizer.fileInfo.size), mayBeLess: true});

// -- 15-byte signatures --

if (checkString('BEGIN:')) {
if (checkString('VCARD', {offset: 6})) {
return {
ext: 'vcf',
mime: 'text/vcard'
};
}

if (checkString('VCALENDAR', {offset: 6})) {
return {
ext: 'ics',
mime: 'text/calendar'
};
}
}

// `raf` is here just to keep all the raw image detectors together.
if (checkString('FUJIFILMCCD-RAW')) {
return {
Expand Down
16 changes: 16 additions & 0 deletions fixture/fixture.vcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BEGIN:VCARD
VERSION:3.0
N:Gump;Forrest;;Mr.,;
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;VALUE=URI;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=WORK,VOICE:(111) 555-1212
TEL;TYPE=HOME,VOICE:(404) 555-1212
ADR;TYPE=WORK,PREF:;;100 Waters Edge;Baytown;LA;30314;United States of America
LABEL;TYPE=WORK,PREF:100 Waters Edge\nBaytown\, LA 30314\nUnited States of America
ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
LABEL;TYPE=HOME:42 Plantation St.\nBaytown\, LA 30314\nUnited States of America
EMAIL:[email protected]
REV:2008-04-24T19:52:43Z
END:VCARD
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@
"stl",
"chm",
"3mf",
"zst"
"zst",
"vcf"
],
"devDependencies": {
"@types/node": "^13.1.4",
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ Returns a set of supported MIME types.
- [`dcm`](https://en.wikipedia.org/wiki/DICOM#Data_format) - DICOM Image File
- [`mpc`](https://en.wikipedia.org/wiki/Musepack) - Musepack (SV7 & SV8)
- [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - iCalendar
- [`vcf`](https://en.wikipedia.org/wiki/VCard) - vCard
- [`glb`](https://github.com/KhronosGroup/glTF) - GL Transmission Format
- [`pcap`](https://wiki.wireshark.org/Development/LibpcapFileFormat) - Libpcap File Format
- [`dsf`](https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf) - Sony DSD Stream File (DSF)
Expand Down
4 changes: 3 additions & 1 deletion supported.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ module.exports = {
'stl',
'chm',
'3mf',
'zst'
'zst',
'vcf'
],
mimeTypes: [
'image/jpeg',
Expand Down Expand Up @@ -238,6 +239,7 @@ module.exports = {
'application/dicom',
'audio/x-musepack',
'text/calendar',
'text/vcard',
'model/gltf-binary',
'application/vnd.tcpdump.pcap',
'audio/x-dsf', // Non-standard
Expand Down

0 comments on commit 29618c8

Please sign in to comment.