file-type 15.0.1 → 16.2.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/core.d.ts +9 -5
- package/core.js +30 -15
- package/package.json +6 -5
- package/readme.md +8 -5
- package/supported.js +9 -5
package/core.d.ts
CHANGED
|
@@ -37,7 +37,6 @@ declare namespace core {
|
|
|
37
37
|
| 'webm'
|
|
38
38
|
| 'mov'
|
|
39
39
|
| 'avi'
|
|
40
|
-
| 'wmv'
|
|
41
40
|
| 'mpg'
|
|
42
41
|
| 'mp2'
|
|
43
42
|
| 'mp3'
|
|
@@ -99,7 +98,6 @@ declare namespace core {
|
|
|
99
98
|
| 'ape'
|
|
100
99
|
| 'wv'
|
|
101
100
|
| 'asf'
|
|
102
|
-
| 'wma'
|
|
103
101
|
| 'dcm'
|
|
104
102
|
| 'mpc'
|
|
105
103
|
| 'ics'
|
|
@@ -136,7 +134,10 @@ declare namespace core {
|
|
|
136
134
|
| 'eps'
|
|
137
135
|
| 'lzh'
|
|
138
136
|
| 'pgp'
|
|
139
|
-
| 'asar'
|
|
137
|
+
| 'asar'
|
|
138
|
+
| 'stl'
|
|
139
|
+
| 'chm'
|
|
140
|
+
| '3mf';
|
|
140
141
|
|
|
141
142
|
type MimeType =
|
|
142
143
|
| 'image/jpeg'
|
|
@@ -175,7 +176,7 @@ declare namespace core {
|
|
|
175
176
|
| 'video/vnd.avi'
|
|
176
177
|
| 'audio/vnd.wave'
|
|
177
178
|
| 'audio/qcelp'
|
|
178
|
-
| 'audio/x-ms-
|
|
179
|
+
| 'audio/x-ms-asf'
|
|
179
180
|
| 'video/x-ms-asf'
|
|
180
181
|
| 'application/vnd.ms-asf'
|
|
181
182
|
| 'video/mpeg'
|
|
@@ -264,7 +265,10 @@ declare namespace core {
|
|
|
264
265
|
| 'image/avif'
|
|
265
266
|
| 'application/x-lzh-compressed'
|
|
266
267
|
| 'application/pgp-encrypted'
|
|
267
|
-
| 'application/x-asar'
|
|
268
|
+
| 'application/x-asar'
|
|
269
|
+
| 'model/stl'
|
|
270
|
+
| 'application/vnd.ms-htmlhelp'
|
|
271
|
+
| 'model/3mf';
|
|
268
272
|
|
|
269
273
|
interface FileTypeResult {
|
|
270
274
|
/**
|
package/core.js
CHANGED
|
@@ -55,15 +55,6 @@ function _check(buffer, headers, options) {
|
|
|
55
55
|
return true;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
async function _checkSequence(sequence, tokenizer, ignoreBytes) {
|
|
59
|
-
const buffer = Buffer.alloc(minimumBytes);
|
|
60
|
-
await tokenizer.ignore(ignoreBytes);
|
|
61
|
-
|
|
62
|
-
await tokenizer.peekBuffer(buffer, {mayBeLess: true});
|
|
63
|
-
|
|
64
|
-
return buffer.includes(Buffer.from(sequence));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
58
|
async function fromTokenizer(tokenizer) {
|
|
68
59
|
try {
|
|
69
60
|
return _fromTokenizer(tokenizer);
|
|
@@ -79,7 +70,6 @@ async function _fromTokenizer(tokenizer) {
|
|
|
79
70
|
const bytesRead = 12;
|
|
80
71
|
const check = (header, options) => _check(buffer, header, options);
|
|
81
72
|
const checkString = (header, options) => check(stringToBytes(header), options);
|
|
82
|
-
const checkSequence = (sequence, ignoreBytes) => _checkSequence(sequence, tokenizer, ignoreBytes);
|
|
83
73
|
|
|
84
74
|
// Keep reading until EOF if the file size is unknown.
|
|
85
75
|
if (!tokenizer.fileInfo.size) {
|
|
@@ -318,6 +308,13 @@ async function _fromTokenizer(tokenizer) {
|
|
|
318
308
|
};
|
|
319
309
|
}
|
|
320
310
|
|
|
311
|
+
if (zipHeader.filename.startsWith('3D/') && zipHeader.filename.endsWith('.model')) {
|
|
312
|
+
return {
|
|
313
|
+
ext: '3mf',
|
|
314
|
+
mime: 'model/3mf'
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
321
318
|
// The docx, xlsx and pptx file types extend the Office Open XML file format:
|
|
322
319
|
// https://en.wikipedia.org/wiki/Office_Open_XML_file_formats
|
|
323
320
|
// We look for:
|
|
@@ -589,9 +586,13 @@ async function _fromTokenizer(tokenizer) {
|
|
|
589
586
|
}
|
|
590
587
|
|
|
591
588
|
if (checkString('%PDF')) {
|
|
589
|
+
await tokenizer.ignore(1350);
|
|
590
|
+
const maxBufferSize = 10 * 1024 * 1024;
|
|
591
|
+
const buffer = Buffer.alloc(Math.min(maxBufferSize, tokenizer.fileInfo.size));
|
|
592
|
+
await tokenizer.readBuffer(buffer, {mayBeLess: true});
|
|
593
|
+
|
|
592
594
|
// Check if this is an Adobe Illustrator file
|
|
593
|
-
|
|
594
|
-
if (isAiFile) {
|
|
595
|
+
if (buffer.includes(Buffer.from('AIPrivateData'))) {
|
|
595
596
|
return {
|
|
596
597
|
ext: 'ai',
|
|
597
598
|
mime: 'application/postscript'
|
|
@@ -880,6 +881,13 @@ async function _fromTokenizer(tokenizer) {
|
|
|
880
881
|
}
|
|
881
882
|
}
|
|
882
883
|
|
|
884
|
+
if (checkString('ITSF')) {
|
|
885
|
+
return {
|
|
886
|
+
ext: 'chm',
|
|
887
|
+
mime: 'application/vnd.ms-htmlhelp'
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
|
|
883
891
|
// -- 6-byte signatures --
|
|
884
892
|
|
|
885
893
|
if (check([0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00])) {
|
|
@@ -920,6 +928,13 @@ async function _fromTokenizer(tokenizer) {
|
|
|
920
928
|
};
|
|
921
929
|
}
|
|
922
930
|
|
|
931
|
+
if (checkString('solid ')) {
|
|
932
|
+
return {
|
|
933
|
+
ext: 'stl',
|
|
934
|
+
mime: 'model/stl'
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
|
|
923
938
|
// -- 7-byte signatures --
|
|
924
939
|
|
|
925
940
|
if (checkString('BLENDER')) {
|
|
@@ -1062,15 +1077,15 @@ async function _fromTokenizer(tokenizer) {
|
|
|
1062
1077
|
if (_check(typeId, [0x40, 0x9E, 0x69, 0xF8, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B])) {
|
|
1063
1078
|
// Found audio:
|
|
1064
1079
|
return {
|
|
1065
|
-
ext: '
|
|
1066
|
-
mime: 'audio/x-ms-
|
|
1080
|
+
ext: 'asf',
|
|
1081
|
+
mime: 'audio/x-ms-asf'
|
|
1067
1082
|
};
|
|
1068
1083
|
}
|
|
1069
1084
|
|
|
1070
1085
|
if (_check(typeId, [0xC0, 0xEF, 0x19, 0xBC, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B])) {
|
|
1071
1086
|
// Found video:
|
|
1072
1087
|
return {
|
|
1073
|
-
ext: '
|
|
1088
|
+
ext: 'asf',
|
|
1074
1089
|
mime: 'video/x-ms-asf'
|
|
1075
1090
|
};
|
|
1076
1091
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.2.0",
|
|
4
4
|
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -133,7 +133,6 @@
|
|
|
133
133
|
"odp",
|
|
134
134
|
"xml",
|
|
135
135
|
"heic",
|
|
136
|
-
"wma",
|
|
137
136
|
"ics",
|
|
138
137
|
"glb",
|
|
139
138
|
"pcap",
|
|
@@ -152,7 +151,6 @@
|
|
|
152
151
|
"f4v",
|
|
153
152
|
"mie",
|
|
154
153
|
"qcp",
|
|
155
|
-
"wmv",
|
|
156
154
|
"asf",
|
|
157
155
|
"ogv",
|
|
158
156
|
"ogm",
|
|
@@ -180,7 +178,10 @@
|
|
|
180
178
|
"eps",
|
|
181
179
|
"lzh",
|
|
182
180
|
"pgp",
|
|
183
|
-
"asar"
|
|
181
|
+
"asar",
|
|
182
|
+
"stl",
|
|
183
|
+
"chm",
|
|
184
|
+
"3mf"
|
|
184
185
|
],
|
|
185
186
|
"devDependencies": {
|
|
186
187
|
"@types/node": "^13.1.4",
|
|
@@ -191,7 +192,7 @@
|
|
|
191
192
|
"xo": "^0.25.3"
|
|
192
193
|
},
|
|
193
194
|
"dependencies": {
|
|
194
|
-
"readable-web-to-node-stream": "^
|
|
195
|
+
"readable-web-to-node-stream": "^3.0.0",
|
|
195
196
|
"strtok3": "^6.0.3",
|
|
196
197
|
"token-types": "^2.0.0",
|
|
197
198
|
"typedarray-to-buffer": "^3.1.5"
|
package/readme.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
# file-type
|
|
1
|
+
# file-type
|
|
2
2
|
|
|
3
3
|
> Detect the file type of a Buffer/Uint8Array/ArrayBuffer
|
|
4
4
|
|
|
5
5
|
The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
|
|
6
6
|
|
|
7
|
+
This package is for detecting binary-based file formats, not text-based formats like `.txt`, `.csv`, `.svg`, etc.
|
|
8
|
+
|
|
7
9
|
## Install
|
|
8
10
|
|
|
9
11
|
```
|
|
@@ -367,8 +369,6 @@ Returns a set of supported MIME types.
|
|
|
367
369
|
- [`ape`](https://en.wikipedia.org/wiki/Monkey%27s_Audio) - Monkey's Audio
|
|
368
370
|
- [`wv`](https://en.wikipedia.org/wiki/WavPack) - WavPack
|
|
369
371
|
- [`asf`](https://en.wikipedia.org/wiki/Advanced_Systems_Format) - Advanced Systems Format
|
|
370
|
-
- [`wma`](https://en.wikipedia.org/wiki/Windows_Media_Audio) - Windows Media Audio
|
|
371
|
-
- [`wmv`](https://en.wikipedia.org/wiki/Windows_Media_Video) - Windows Media Video
|
|
372
372
|
- [`dcm`](https://en.wikipedia.org/wiki/DICOM#Data_format) - DICOM Image File
|
|
373
373
|
- [`mpc`](https://en.wikipedia.org/wiki/Musepack) - Musepack (SV7 & SV8)
|
|
374
374
|
- [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - iCalendar
|
|
@@ -403,13 +403,16 @@ Returns a set of supported MIME types.
|
|
|
403
403
|
- [`lzh`](https://en.wikipedia.org/wiki/LHA_(file_format)) - LZH archive
|
|
404
404
|
- [`pgp`](https://en.wikipedia.org/wiki/Pretty_Good_Privacy) - Pretty Good Privacy
|
|
405
405
|
- [`asar`](https://github.com/electron/asar#format) - Archive format primarily used to enclose Electron applications
|
|
406
|
+
- [`stl`](https://en.wikipedia.org/wiki/STL_(file_format)) - Standard Tesselated Geometry File Format (ASCII only)
|
|
407
|
+
- [`chm`](https://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help) - Microsoft Compiled HTML Help
|
|
408
|
+
- [`3mf`](https://en.wikipedia.org/wiki/3D_Manufacturing_Format) - 3D Manufacturing Format
|
|
406
409
|
|
|
407
410
|
*Pull requests are welcome for additional commonly used file types.*
|
|
408
411
|
|
|
409
412
|
The following file types will not be accepted:
|
|
410
413
|
- [MS-CFB: Microsoft Compound File Binary File Format based formats](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-cfb/53989ce4-7b05-4f8d-829b-d08d6148375b), too old and difficult to parse:
|
|
411
|
-
- `.doc` - Microsoft Word 97-2003 Document
|
|
412
|
-
- `.xls` - Microsoft Excel 97-2003 Document
|
|
414
|
+
- `.doc` - Microsoft Word 97-2003 Document
|
|
415
|
+
- `.xls` - Microsoft Excel 97-2003 Document
|
|
413
416
|
- `.ppt` - Microsoft PowerPoint97-2003 Document
|
|
414
417
|
- `.msi` - Microsoft Windows Installer
|
|
415
418
|
- `.csv` - [Reason.](https://github.com/sindresorhus/file-type/issues/264#issuecomment-568439196)
|
package/supported.js
CHANGED
|
@@ -98,8 +98,6 @@ module.exports = {
|
|
|
98
98
|
'ktx',
|
|
99
99
|
'ape',
|
|
100
100
|
'wv',
|
|
101
|
-
'wmv',
|
|
102
|
-
'wma',
|
|
103
101
|
'dcm',
|
|
104
102
|
'ics',
|
|
105
103
|
'glb',
|
|
@@ -134,7 +132,10 @@ module.exports = {
|
|
|
134
132
|
'eps',
|
|
135
133
|
'lzh',
|
|
136
134
|
'pgp',
|
|
137
|
-
'asar'
|
|
135
|
+
'asar',
|
|
136
|
+
'stl',
|
|
137
|
+
'chm',
|
|
138
|
+
'3mf'
|
|
138
139
|
],
|
|
139
140
|
mimeTypes: [
|
|
140
141
|
'image/jpeg',
|
|
@@ -173,7 +174,7 @@ module.exports = {
|
|
|
173
174
|
'video/vnd.avi',
|
|
174
175
|
'audio/vnd.wave',
|
|
175
176
|
'audio/qcelp',
|
|
176
|
-
'audio/x-ms-
|
|
177
|
+
'audio/x-ms-asf',
|
|
177
178
|
'video/x-ms-asf',
|
|
178
179
|
'application/vnd.ms-asf',
|
|
179
180
|
'video/mpeg',
|
|
@@ -262,6 +263,9 @@ module.exports = {
|
|
|
262
263
|
'image/avif',
|
|
263
264
|
'application/x-lzh-compressed',
|
|
264
265
|
'application/pgp-encrypted',
|
|
265
|
-
'application/x-asar'
|
|
266
|
+
'application/x-asar',
|
|
267
|
+
'model/stl',
|
|
268
|
+
'application/vnd.ms-htmlhelp',
|
|
269
|
+
'model/3mf'
|
|
266
270
|
]
|
|
267
271
|
};
|