Skip to content

Commit 29618c8

Browse files
mdarticBorewit
andauthored
Add support for VCF (and fix ICS detection) (#451)
Co-authored-by: Borewit <[email protected]>
1 parent 6ab25f3 commit 29618c8

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

core.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ declare namespace core {
139139
| 'stl'
140140
| 'chm'
141141
| '3mf'
142-
| 'zst';
142+
| 'zst'
143+
| 'vcf';
143144

144145
type MimeType =
145146
| 'image/jpeg'
@@ -240,6 +241,7 @@ declare namespace core {
240241
| 'application/dicom'
241242
| 'audio/x-musepack'
242243
| 'text/calendar'
244+
| 'text/vcard'
243245
| 'model/gltf-binary'
244246
| 'application/vnd.tcpdump.pcap'
245247
| 'audio/x-dsf' // Non-standard

core.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -911,13 +911,6 @@ async function _fromTokenizer(tokenizer) {
911911
};
912912
}
913913

914-
if (checkString('BEGIN:')) {
915-
return {
916-
ext: 'ics',
917-
mime: 'text/calendar'
918-
};
919-
}
920-
921914
if (check([0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C])) {
922915
return {
923916
ext: '7z',
@@ -1213,6 +1206,24 @@ async function _fromTokenizer(tokenizer) {
12131206
// Increase sample size from 12 to 256.
12141207
await tokenizer.peekBuffer(buffer, {length: Math.min(256, tokenizer.fileInfo.size), mayBeLess: true});
12151208

1209+
// -- 15-byte signatures --
1210+
1211+
if (checkString('BEGIN:')) {
1212+
if (checkString('VCARD', {offset: 6})) {
1213+
return {
1214+
ext: 'vcf',
1215+
mime: 'text/vcard'
1216+
};
1217+
}
1218+
1219+
if (checkString('VCALENDAR', {offset: 6})) {
1220+
return {
1221+
ext: 'ics',
1222+
mime: 'text/calendar'
1223+
};
1224+
}
1225+
}
1226+
12161227
// `raf` is here just to keep all the raw image detectors together.
12171228
if (checkString('FUJIFILMCCD-RAW')) {
12181229
return {

fixture/fixture.vcf

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
BEGIN:VCARD
2+
VERSION:3.0
3+
N:Gump;Forrest;;Mr.,;
4+
FN:Forrest Gump
5+
ORG:Bubba Gump Shrimp Co.
6+
TITLE:Shrimp Man
7+
PHOTO;VALUE=URI;TYPE=GIF:http://www.example.com/dir_photos/my_photo.gif
8+
TEL;TYPE=WORK,VOICE:(111) 555-1212
9+
TEL;TYPE=HOME,VOICE:(404) 555-1212
10+
ADR;TYPE=WORK,PREF:;;100 Waters Edge;Baytown;LA;30314;United States of America
11+
LABEL;TYPE=WORK,PREF:100 Waters Edge\nBaytown\, LA 30314\nUnited States of America
12+
ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
13+
LABEL;TYPE=HOME:42 Plantation St.\nBaytown\, LA 30314\nUnited States of America
14+
15+
REV:2008-04-24T19:52:43Z
16+
END:VCARD

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@
183183
"stl",
184184
"chm",
185185
"3mf",
186-
"zst"
186+
"zst",
187+
"vcf"
187188
],
188189
"devDependencies": {
189190
"@types/node": "^13.1.4",

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ Returns a set of supported MIME types.
374374
- [`dcm`](https://en.wikipedia.org/wiki/DICOM#Data_format) - DICOM Image File
375375
- [`mpc`](https://en.wikipedia.org/wiki/Musepack) - Musepack (SV7 & SV8)
376376
- [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - iCalendar
377+
- [`vcf`](https://en.wikipedia.org/wiki/VCard) - vCard
377378
- [`glb`](https://github.com/KhronosGroup/glTF) - GL Transmission Format
378379
- [`pcap`](https://wiki.wireshark.org/Development/LibpcapFileFormat) - Libpcap File Format
379380
- [`dsf`](https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf) - Sony DSD Stream File (DSF)

supported.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ module.exports = {
137137
'stl',
138138
'chm',
139139
'3mf',
140-
'zst'
140+
'zst',
141+
'vcf'
141142
],
142143
mimeTypes: [
143144
'image/jpeg',
@@ -238,6 +239,7 @@ module.exports = {
238239
'application/dicom',
239240
'audio/x-musepack',
240241
'text/calendar',
242+
'text/vcard',
241243
'model/gltf-binary',
242244
'application/vnd.tcpdump.pcap',
243245
'audio/x-dsf', // Non-standard

0 commit comments

Comments
 (0)