file-type 3.5.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +36 -2
- package/package.json +6 -3
- package/readme.md +60 -57
package/index.js
CHANGED
|
@@ -32,6 +32,13 @@ module.exports = function (buf) {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
if (buf[0] === 0x46 && buf[1] === 0x4C && buf[2] === 0x49 && buf[3] === 0x46) {
|
|
36
|
+
return {
|
|
37
|
+
ext: 'flif',
|
|
38
|
+
mime: 'image/flif'
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
35
42
|
// needs to be before `tif` check
|
|
36
43
|
if (((buf[0] === 0x49 && buf[1] === 0x49 && buf[2] === 0x2A && buf[3] === 0x0) || (buf[0] === 0x4D && buf[1] === 0x4D && buf[2] === 0x0 && buf[3] === 0x2A)) && buf[8] === 0x43 && buf[9] === 0x52) {
|
|
37
44
|
return {
|
|
@@ -218,6 +225,14 @@ module.exports = function (buf) {
|
|
|
218
225
|
};
|
|
219
226
|
}
|
|
220
227
|
|
|
228
|
+
// needs to be before `ogg` check
|
|
229
|
+
if (buf[28] === 0x4F && buf[29] === 0x70 && buf[30] === 0x75 && buf[31] === 0x73 && buf[32] === 0x48 && buf[33] === 0x65 && buf[34] === 0x61 && buf[35] === 0x64) {
|
|
230
|
+
return {
|
|
231
|
+
ext: 'opus',
|
|
232
|
+
mime: 'audio/opus'
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
221
236
|
if (buf[0] === 0x4F && buf[1] === 0x67 && buf[2] === 0x67 && buf[3] === 0x53) {
|
|
222
237
|
return {
|
|
223
238
|
ext: 'ogg',
|
|
@@ -274,14 +289,26 @@ module.exports = function (buf) {
|
|
|
274
289
|
};
|
|
275
290
|
}
|
|
276
291
|
|
|
277
|
-
if (
|
|
292
|
+
if (
|
|
293
|
+
(buf[0] === 0x77 && buf[1] === 0x4F && buf[2] === 0x46 && buf[3] === 0x46) &&
|
|
294
|
+
(
|
|
295
|
+
(buf[4] === 0x00 && buf[5] === 0x01 && buf[6] === 0x00 && buf[7] === 0x00) ||
|
|
296
|
+
(buf[4] === 0x4F && buf[5] === 0x54 && buf[6] === 0x54 && buf[7] === 0x4F)
|
|
297
|
+
)
|
|
298
|
+
) {
|
|
278
299
|
return {
|
|
279
300
|
ext: 'woff',
|
|
280
301
|
mime: 'application/font-woff'
|
|
281
302
|
};
|
|
282
303
|
}
|
|
283
304
|
|
|
284
|
-
if (
|
|
305
|
+
if (
|
|
306
|
+
(buf[0] === 0x77 && buf[1] === 0x4F && buf[2] === 0x46 && buf[3] === 0x32) &&
|
|
307
|
+
(
|
|
308
|
+
(buf[4] === 0x00 && buf[5] === 0x01 && buf[6] === 0x00 && buf[7] === 0x00) ||
|
|
309
|
+
(buf[4] === 0x4F && buf[5] === 0x54 && buf[6] === 0x54 && buf[7] === 0x4F)
|
|
310
|
+
)
|
|
311
|
+
) {
|
|
285
312
|
return {
|
|
286
313
|
ext: 'woff2',
|
|
287
314
|
mime: 'application/font-woff'
|
|
@@ -414,5 +441,12 @@ module.exports = function (buf) {
|
|
|
414
441
|
};
|
|
415
442
|
}
|
|
416
443
|
|
|
444
|
+
if (buf[0] === 0xD0 && buf[1] === 0xCF && buf[2] === 0x11 && buf[3] === 0xE0 && buf[4] === 0xA1 && buf[5] === 0xB1 && buf[6] === 0x1A && buf[7] === 0xE1) {
|
|
445
|
+
return {
|
|
446
|
+
ext: 'msi',
|
|
447
|
+
mime: 'application/x-msi'
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
417
451
|
return null;
|
|
418
452
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "Detect the file type of a Buffer/Uint8Array",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"png",
|
|
44
44
|
"gif",
|
|
45
45
|
"webp",
|
|
46
|
+
"flif",
|
|
46
47
|
"cr2",
|
|
47
48
|
"tif",
|
|
48
49
|
"bmp",
|
|
@@ -66,6 +67,7 @@
|
|
|
66
67
|
"mp3",
|
|
67
68
|
"m4a",
|
|
68
69
|
"ogg",
|
|
70
|
+
"opus",
|
|
69
71
|
"flac",
|
|
70
72
|
"wav",
|
|
71
73
|
"amr",
|
|
@@ -90,11 +92,12 @@
|
|
|
90
92
|
"ar",
|
|
91
93
|
"rpm",
|
|
92
94
|
"Z",
|
|
93
|
-
"lz"
|
|
95
|
+
"lz",
|
|
96
|
+
"msi"
|
|
94
97
|
],
|
|
95
98
|
"devDependencies": {
|
|
96
99
|
"ava": "*",
|
|
97
|
-
"read-chunk": "^
|
|
100
|
+
"read-chunk": "^2.0.0",
|
|
98
101
|
"xo": "*"
|
|
99
102
|
}
|
|
100
103
|
}
|
package/readme.md
CHANGED
|
@@ -61,75 +61,78 @@ xhr.send();
|
|
|
61
61
|
|
|
62
62
|
### fileType(buffer)
|
|
63
63
|
|
|
64
|
-
Returns an
|
|
64
|
+
Returns an `Object` (or `null` when no match) with:
|
|
65
65
|
|
|
66
66
|
- `ext` - one of the [supported file types](#supported-file-types)
|
|
67
67
|
- `mime` - the [MIME type](http://en.wikipedia.org/wiki/Internet_media_type)
|
|
68
68
|
|
|
69
69
|
#### buffer
|
|
70
70
|
|
|
71
|
-
Type: `
|
|
71
|
+
Type: `Buffer` `Uint8Array`
|
|
72
72
|
|
|
73
73
|
It only needs the first 262 bytes.
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
## Supported file types
|
|
77
77
|
|
|
78
|
-
- `jpg`
|
|
79
|
-
- `png`
|
|
80
|
-
- `gif`
|
|
81
|
-
- `webp`
|
|
82
|
-
- `
|
|
83
|
-
- `
|
|
84
|
-
- `
|
|
85
|
-
- `
|
|
86
|
-
- `
|
|
87
|
-
- `
|
|
88
|
-
- `
|
|
89
|
-
- `
|
|
90
|
-
- `
|
|
91
|
-
- `
|
|
92
|
-
- `
|
|
93
|
-
- `
|
|
94
|
-
- `
|
|
95
|
-
- `
|
|
96
|
-
- `
|
|
97
|
-
- `
|
|
98
|
-
- `
|
|
99
|
-
- `
|
|
100
|
-
- `
|
|
101
|
-
- `
|
|
102
|
-
- `
|
|
103
|
-
- `
|
|
104
|
-
- `
|
|
105
|
-
- `
|
|
106
|
-
- `
|
|
107
|
-
- `
|
|
78
|
+
- [`jpg`](https://en.wikipedia.org/wiki/JPEG)
|
|
79
|
+
- [`png`](https://en.wikipedia.org/wiki/Portable_Network_Graphics)
|
|
80
|
+
- [`gif`](https://en.wikipedia.org/wiki/GIF)
|
|
81
|
+
- [`webp`](https://en.wikipedia.org/wiki/WebP)
|
|
82
|
+
- [`flif`](https://en.wikipedia.org/wiki/Free_Lossless_Image_Format)
|
|
83
|
+
- [`cr2`](http://fileinfo.com/extension/cr2)
|
|
84
|
+
- [`tif`](https://en.wikipedia.org/wiki/Tagged_Image_File_Format)
|
|
85
|
+
- [`bmp`](https://en.wikipedia.org/wiki/BMP_file_format)
|
|
86
|
+
- [`jxr`](https://en.wikipedia.org/wiki/JPEG_XR)
|
|
87
|
+
- [`psd`](https://en.wikipedia.org/wiki/Adobe_Photoshop#File_format)
|
|
88
|
+
- [`zip`](https://en.wikipedia.org/wiki/Zip_(file_format))
|
|
89
|
+
- [`tar`](https://en.wikipedia.org/wiki/Tar_(computing)#File_format)
|
|
90
|
+
- [`rar`](https://en.wikipedia.org/wiki/RAR_(file_format))
|
|
91
|
+
- [`gz`](https://en.wikipedia.org/wiki/Gzip)
|
|
92
|
+
- [`bz2`](https://en.wikipedia.org/wiki/Bzip2)
|
|
93
|
+
- [`7z`](https://en.wikipedia.org/wiki/7z)
|
|
94
|
+
- [`dmg`](https://en.wikipedia.org/wiki/Apple_Disk_Image)
|
|
95
|
+
- [`mp4`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#Filename_extensions)
|
|
96
|
+
- [`m4v`](https://en.wikipedia.org/wiki/M4V)
|
|
97
|
+
- [`mid`](https://en.wikipedia.org/wiki/MIDI)
|
|
98
|
+
- [`mkv`](https://en.wikipedia.org/wiki/Matroska)
|
|
99
|
+
- [`webm`](https://en.wikipedia.org/wiki/WebM)
|
|
100
|
+
- [`mov`](https://en.wikipedia.org/wiki/QuickTime_File_Format)
|
|
101
|
+
- [`avi`](https://en.wikipedia.org/wiki/Audio_Video_Interleave)
|
|
102
|
+
- [`wmv`](https://en.wikipedia.org/wiki/Windows_Media_Video)
|
|
103
|
+
- [`mpg`](https://en.wikipedia.org/wiki/MPEG-1)
|
|
104
|
+
- [`mp3`](https://en.wikipedia.org/wiki/MP3)
|
|
105
|
+
- [`m4a`](https://en.wikipedia.org/wiki/MPEG-4_Part_14#.MP4_versus_.M4A)
|
|
106
|
+
- [`ogg`](https://en.wikipedia.org/wiki/Ogg)
|
|
107
|
+
- [`opus`](https://en.wikipedia.org/wiki/Opus_(audio_format))
|
|
108
|
+
- [`flac`](https://en.wikipedia.org/wiki/FLAC)
|
|
109
|
+
- [`wav`](https://en.wikipedia.org/wiki/WAV)
|
|
108
110
|
- [`amr`](https://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec)
|
|
109
|
-
- `pdf`
|
|
110
|
-
- `epub`
|
|
111
|
-
- `exe`
|
|
112
|
-
- `swf`
|
|
113
|
-
- `rtf`
|
|
114
|
-
- `woff`
|
|
115
|
-
- `woff2`
|
|
116
|
-
- `eot`
|
|
117
|
-
- `ttf`
|
|
118
|
-
- `otf`
|
|
119
|
-
- `ico`
|
|
120
|
-
- `flv`
|
|
121
|
-
- `ps`
|
|
122
|
-
- `xz`
|
|
123
|
-
- `sqlite`
|
|
124
|
-
- `nes`
|
|
125
|
-
- `crx`
|
|
126
|
-
- `xpi`
|
|
127
|
-
- `cab`
|
|
128
|
-
- `deb`
|
|
129
|
-
- `ar`
|
|
130
|
-
- `rpm`
|
|
131
|
-
- `Z`
|
|
132
|
-
- `lz`
|
|
111
|
+
- [`pdf`](https://en.wikipedia.org/wiki/Portable_Document_Format)
|
|
112
|
+
- [`epub`](https://en.wikipedia.org/wiki/EPUB)
|
|
113
|
+
- [`exe`](https://en.wikipedia.org/wiki/.exe)
|
|
114
|
+
- [`swf`](https://en.wikipedia.org/wiki/SWF)
|
|
115
|
+
- [`rtf`](https://en.wikipedia.org/wiki/Rich_Text_Format)
|
|
116
|
+
- [`woff`](https://en.wikipedia.org/wiki/Web_Open_Font_Format)
|
|
117
|
+
- [`woff2`](https://en.wikipedia.org/wiki/Web_Open_Font_Format)
|
|
118
|
+
- [`eot`](https://en.wikipedia.org/wiki/Embedded_OpenType)
|
|
119
|
+
- [`ttf`](https://en.wikipedia.org/wiki/TrueType)
|
|
120
|
+
- [`otf`](https://en.wikipedia.org/wiki/OpenType)
|
|
121
|
+
- [`ico`](https://en.wikipedia.org/wiki/ICO_(file_format))
|
|
122
|
+
- [`flv`](https://en.wikipedia.org/wiki/Flash_Video)
|
|
123
|
+
- [`ps`](https://en.wikipedia.org/wiki/Postscript)
|
|
124
|
+
- [`xz`](https://en.wikipedia.org/wiki/Xz)
|
|
125
|
+
- [`sqlite`](https://www.sqlite.org/fileformat2.html)
|
|
126
|
+
- [`nes`](http://fileinfo.com/extension/nes)
|
|
127
|
+
- [`crx`](https://developer.chrome.com/extensions/crx)
|
|
128
|
+
- [`xpi`](https://en.wikipedia.org/wiki/XPInstall)
|
|
129
|
+
- [`cab`](https://en.wikipedia.org/wiki/Cabinet_(file_format))
|
|
130
|
+
- [`deb`](https://en.wikipedia.org/wiki/Deb_(file_format))
|
|
131
|
+
- [`ar`](https://en.wikipedia.org/wiki/Ar_(Unix))
|
|
132
|
+
- [`rpm`](http://fileinfo.com/extension/rpm)
|
|
133
|
+
- [`Z`](http://fileinfo.com/extension/z)
|
|
134
|
+
- [`lz`](https://en.wikipedia.org/wiki/Lzip)
|
|
135
|
+
- [`msi`](https://en.wikipedia.org/wiki/Windows_Installer)
|
|
133
136
|
|
|
134
137
|
*SVG isn't included as it requires the whole file to be read, but you can get it [here](https://github.com/sindresorhus/is-svg).*
|
|
135
138
|
|
|
@@ -143,4 +146,4 @@ It only needs the first 262 bytes.
|
|
|
143
146
|
|
|
144
147
|
## License
|
|
145
148
|
|
|
146
|
-
MIT © [Sindre Sorhus](
|
|
149
|
+
MIT © [Sindre Sorhus](https://sindresorhus.com)
|