file-type 14.7.1 → 16.0.1
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 +7 -7
- package/core.js +23 -11
- package/package.json +6 -6
- package/readme.md +9 -6
- package/supported.js +7 -7
- package/util.js +13 -26
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'
|
|
@@ -73,7 +72,7 @@ declare namespace core {
|
|
|
73
72
|
| 'rpm'
|
|
74
73
|
| 'Z'
|
|
75
74
|
| 'lz'
|
|
76
|
-
| '
|
|
75
|
+
| 'cfb'
|
|
77
76
|
| 'mxf'
|
|
78
77
|
| 'mts'
|
|
79
78
|
| 'wasm'
|
|
@@ -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,8 @@ declare namespace core {
|
|
|
136
134
|
| 'eps'
|
|
137
135
|
| 'lzh'
|
|
138
136
|
| 'pgp'
|
|
139
|
-
| 'asar'
|
|
137
|
+
| 'asar'
|
|
138
|
+
| 'stl';
|
|
140
139
|
|
|
141
140
|
type MimeType =
|
|
142
141
|
| 'image/jpeg'
|
|
@@ -175,7 +174,7 @@ declare namespace core {
|
|
|
175
174
|
| 'video/vnd.avi'
|
|
176
175
|
| 'audio/vnd.wave'
|
|
177
176
|
| 'audio/qcelp'
|
|
178
|
-
| 'audio/x-ms-
|
|
177
|
+
| 'audio/x-ms-asf'
|
|
179
178
|
| 'video/x-ms-asf'
|
|
180
179
|
| 'application/vnd.ms-asf'
|
|
181
180
|
| 'video/mpeg'
|
|
@@ -214,7 +213,7 @@ declare namespace core {
|
|
|
214
213
|
| 'application/x-rpm'
|
|
215
214
|
| 'application/x-compress'
|
|
216
215
|
| 'application/x-lzip'
|
|
217
|
-
| 'application/x-
|
|
216
|
+
| 'application/x-cfb'
|
|
218
217
|
| 'application/x-mie'
|
|
219
218
|
| 'application/x-apache-arrow'
|
|
220
219
|
| 'application/mxf'
|
|
@@ -264,7 +263,8 @@ declare namespace core {
|
|
|
264
263
|
| 'image/avif'
|
|
265
264
|
| 'application/x-lzh-compressed'
|
|
266
265
|
| 'application/pgp-encrypted'
|
|
267
|
-
| 'application/x-asar'
|
|
266
|
+
| 'application/x-asar'
|
|
267
|
+
| 'model/stl';
|
|
268
268
|
|
|
269
269
|
interface FileTypeResult {
|
|
270
270
|
/**
|
package/core.js
CHANGED
|
@@ -920,6 +920,13 @@ async function _fromTokenizer(tokenizer) {
|
|
|
920
920
|
};
|
|
921
921
|
}
|
|
922
922
|
|
|
923
|
+
if (checkString('solid ')) {
|
|
924
|
+
return {
|
|
925
|
+
ext: 'stl',
|
|
926
|
+
mime: 'model/stl'
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
|
|
923
930
|
// -- 7-byte signatures --
|
|
924
931
|
|
|
925
932
|
if (checkString('BLENDER')) {
|
|
@@ -967,6 +974,10 @@ async function _fromTokenizer(tokenizer) {
|
|
|
967
974
|
|
|
968
975
|
do {
|
|
969
976
|
const chunk = await readChunkHeader();
|
|
977
|
+
if (chunk.length < 0) {
|
|
978
|
+
return; // Invalid chunk length
|
|
979
|
+
}
|
|
980
|
+
|
|
970
981
|
switch (chunk.type) {
|
|
971
982
|
case 'IDAT':
|
|
972
983
|
return {
|
|
@@ -981,7 +992,7 @@ async function _fromTokenizer(tokenizer) {
|
|
|
981
992
|
default:
|
|
982
993
|
await tokenizer.ignore(chunk.length + 4); // Ignore chunk-data + CRC
|
|
983
994
|
}
|
|
984
|
-
} while (tokenizer.position < tokenizer.fileInfo.size);
|
|
995
|
+
} while (tokenizer.position + 8 < tokenizer.fileInfo.size);
|
|
985
996
|
|
|
986
997
|
return {
|
|
987
998
|
ext: 'png',
|
|
@@ -1058,15 +1069,15 @@ async function _fromTokenizer(tokenizer) {
|
|
|
1058
1069
|
if (_check(typeId, [0x40, 0x9E, 0x69, 0xF8, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B])) {
|
|
1059
1070
|
// Found audio:
|
|
1060
1071
|
return {
|
|
1061
|
-
ext: '
|
|
1062
|
-
mime: 'audio/x-ms-
|
|
1072
|
+
ext: 'asf',
|
|
1073
|
+
mime: 'audio/x-ms-asf'
|
|
1063
1074
|
};
|
|
1064
1075
|
}
|
|
1065
1076
|
|
|
1066
1077
|
if (_check(typeId, [0xC0, 0xEF, 0x19, 0xBC, 0x4D, 0x5B, 0xCF, 0x11, 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B])) {
|
|
1067
1078
|
// Found video:
|
|
1068
1079
|
return {
|
|
1069
|
-
ext: '
|
|
1080
|
+
ext: 'asf',
|
|
1070
1081
|
mime: 'video/x-ms-asf'
|
|
1071
1082
|
};
|
|
1072
1083
|
}
|
|
@@ -1169,6 +1180,14 @@ async function _fromTokenizer(tokenizer) {
|
|
|
1169
1180
|
};
|
|
1170
1181
|
}
|
|
1171
1182
|
|
|
1183
|
+
if (check([0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1])) {
|
|
1184
|
+
// Detected Microsoft Compound File Binary File (MS-CFB) Format.
|
|
1185
|
+
return {
|
|
1186
|
+
ext: 'cfb',
|
|
1187
|
+
mime: 'application/x-cfb'
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1172
1191
|
// Increase sample size from 12 to 256.
|
|
1173
1192
|
await tokenizer.peekBuffer(buffer, {length: Math.min(256, tokenizer.fileInfo.size), mayBeLess: true});
|
|
1174
1193
|
|
|
@@ -1212,13 +1231,6 @@ async function _fromTokenizer(tokenizer) {
|
|
|
1212
1231
|
}
|
|
1213
1232
|
}
|
|
1214
1233
|
|
|
1215
|
-
if (check([0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E])) {
|
|
1216
|
-
return {
|
|
1217
|
-
ext: 'msi',
|
|
1218
|
-
mime: 'application/x-msi'
|
|
1219
|
-
};
|
|
1220
|
-
}
|
|
1221
|
-
|
|
1222
1234
|
if (check([0x06, 0x0E, 0x2B, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0D, 0x01, 0x02, 0x01, 0x01, 0x02])) {
|
|
1223
1235
|
return {
|
|
1224
1236
|
ext: 'mxf',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.1",
|
|
4
4
|
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"mime",
|
|
32
32
|
"file",
|
|
33
33
|
"type",
|
|
34
|
+
"magic",
|
|
34
35
|
"archive",
|
|
35
36
|
"image",
|
|
36
37
|
"img",
|
|
@@ -111,7 +112,7 @@
|
|
|
111
112
|
"rpm",
|
|
112
113
|
"Z",
|
|
113
114
|
"lz",
|
|
114
|
-
"
|
|
115
|
+
"cfb",
|
|
115
116
|
"mxf",
|
|
116
117
|
"mts",
|
|
117
118
|
"wasm",
|
|
@@ -132,7 +133,6 @@
|
|
|
132
133
|
"odp",
|
|
133
134
|
"xml",
|
|
134
135
|
"heic",
|
|
135
|
-
"wma",
|
|
136
136
|
"ics",
|
|
137
137
|
"glb",
|
|
138
138
|
"pcap",
|
|
@@ -151,7 +151,6 @@
|
|
|
151
151
|
"f4v",
|
|
152
152
|
"mie",
|
|
153
153
|
"qcp",
|
|
154
|
-
"wmv",
|
|
155
154
|
"asf",
|
|
156
155
|
"ogv",
|
|
157
156
|
"ogm",
|
|
@@ -179,7 +178,8 @@
|
|
|
179
178
|
"eps",
|
|
180
179
|
"lzh",
|
|
181
180
|
"pgp",
|
|
182
|
-
"asar"
|
|
181
|
+
"asar",
|
|
182
|
+
"stl"
|
|
183
183
|
],
|
|
184
184
|
"devDependencies": {
|
|
185
185
|
"@types/node": "^13.1.4",
|
|
@@ -190,7 +190,7 @@
|
|
|
190
190
|
"xo": "^0.25.3"
|
|
191
191
|
},
|
|
192
192
|
"dependencies": {
|
|
193
|
-
"readable-web-to-node-stream": "^
|
|
193
|
+
"readable-web-to-node-stream": "^3.0.0",
|
|
194
194
|
"strtok3": "^6.0.3",
|
|
195
195
|
"token-types": "^2.0.0",
|
|
196
196
|
"typedarray-to-buffer": "^3.1.5"
|
package/readme.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
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
|
```
|
|
@@ -343,7 +345,7 @@ Returns a set of supported MIME types.
|
|
|
343
345
|
- [`rpm`](https://fileinfo.com/extension/rpm)
|
|
344
346
|
- [`Z`](https://fileinfo.com/extension/z)
|
|
345
347
|
- [`lz`](https://en.wikipedia.org/wiki/Lzip)
|
|
346
|
-
- [`
|
|
348
|
+
- [`cfb`](https://en.wikipedia.org/wiki/Compound_File_Binary_Format)
|
|
347
349
|
- [`mxf`](https://en.wikipedia.org/wiki/Material_Exchange_Format)
|
|
348
350
|
- [`mts`](https://en.wikipedia.org/wiki/.m2ts)
|
|
349
351
|
- [`wasm`](https://en.wikipedia.org/wiki/WebAssembly)
|
|
@@ -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)
|
|
406
407
|
|
|
407
408
|
*Pull requests are welcome for additional commonly used file types.*
|
|
408
409
|
|
|
409
410
|
The following file types will not be accepted:
|
|
410
|
-
-
|
|
411
|
-
- `.
|
|
412
|
-
- `.
|
|
411
|
+
- [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:
|
|
412
|
+
- `.doc` - Microsoft Word 97-2003 Document
|
|
413
|
+
- `.xls` - Microsoft Excel 97-2003 Document
|
|
414
|
+
- `.ppt` - Microsoft PowerPoint97-2003 Document
|
|
415
|
+
- `.msi` - Microsoft Windows Installer
|
|
413
416
|
- `.csv` - [Reason.](https://github.com/sindresorhus/file-type/issues/264#issuecomment-568439196)
|
|
414
417
|
- `.svg` - Detecting it requires a full-blown parser. Check out [`is-svg`](https://github.com/sindresorhus/is-svg) for something that mostly works.
|
|
415
418
|
|
package/supported.js
CHANGED
|
@@ -72,7 +72,7 @@ module.exports = {
|
|
|
72
72
|
'rpm',
|
|
73
73
|
'Z',
|
|
74
74
|
'lz',
|
|
75
|
-
'
|
|
75
|
+
'cfb',
|
|
76
76
|
'mxf',
|
|
77
77
|
'mts',
|
|
78
78
|
'blend',
|
|
@@ -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,8 @@ module.exports = {
|
|
|
134
132
|
'eps',
|
|
135
133
|
'lzh',
|
|
136
134
|
'pgp',
|
|
137
|
-
'asar'
|
|
135
|
+
'asar',
|
|
136
|
+
'stl'
|
|
138
137
|
],
|
|
139
138
|
mimeTypes: [
|
|
140
139
|
'image/jpeg',
|
|
@@ -173,7 +172,7 @@ module.exports = {
|
|
|
173
172
|
'video/vnd.avi',
|
|
174
173
|
'audio/vnd.wave',
|
|
175
174
|
'audio/qcelp',
|
|
176
|
-
'audio/x-ms-
|
|
175
|
+
'audio/x-ms-asf',
|
|
177
176
|
'video/x-ms-asf',
|
|
178
177
|
'application/vnd.ms-asf',
|
|
179
178
|
'video/mpeg',
|
|
@@ -212,7 +211,7 @@ module.exports = {
|
|
|
212
211
|
'application/x-rpm',
|
|
213
212
|
'application/x-compress',
|
|
214
213
|
'application/x-lzip',
|
|
215
|
-
'application/x-
|
|
214
|
+
'application/x-cfb',
|
|
216
215
|
'application/x-mie',
|
|
217
216
|
'application/mxf',
|
|
218
217
|
'video/mp2t',
|
|
@@ -262,6 +261,7 @@ module.exports = {
|
|
|
262
261
|
'image/avif',
|
|
263
262
|
'application/x-lzh-compressed',
|
|
264
263
|
'application/pgp-encrypted',
|
|
265
|
-
'application/x-asar'
|
|
264
|
+
'application/x-asar',
|
|
265
|
+
'model/stl'
|
|
266
266
|
]
|
|
267
267
|
};
|
package/util.js
CHANGED
|
@@ -2,43 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
exports.stringToBytes = string => [...string].map(character => character.charCodeAt(0));
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
5
|
+
/**
|
|
6
|
+
Checks whether the TAR checksum is valid.
|
|
9
7
|
|
|
8
|
+
@param {Buffer} buffer - The TAR header `[offset ... offset + 512]`.
|
|
9
|
+
@param {number} offset - TAR header offset.
|
|
10
|
+
@returns {boolean} `true` if the TAR checksum is valid, otherwise `false`.
|
|
11
|
+
*/
|
|
12
|
+
exports.tarHeaderChecksumMatches = (buffer, offset = 0) => {
|
|
10
13
|
const readSum = parseInt(buffer.toString('utf8', 148, 154).replace(/\0.*$/, '').trim(), 8); // Read sum in header
|
|
11
14
|
if (isNaN(readSum)) {
|
|
12
15
|
return false;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
let sum = 8 * 0x20; // Initialize signed bit sum
|
|
16
19
|
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
for (let i = 0; i < 148; i++) {
|
|
21
|
-
const byte = buffer[i];
|
|
22
|
-
sum += byte;
|
|
23
|
-
signedBitSum += byte & MASK_8TH_BIT; // Add signed bit to signed bit sum
|
|
20
|
+
for (let i = offset; i < offset + 148; i++) {
|
|
21
|
+
sum += buffer[i];
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (let i = 156; i < 512; i++) {
|
|
29
|
-
const byte = buffer[i];
|
|
30
|
-
sum += byte;
|
|
31
|
-
signedBitSum += byte & MASK_8TH_BIT; // Add signed bit to signed bit sum
|
|
24
|
+
for (let i = offset + 156; i < offset + 512; i++) {
|
|
25
|
+
sum += buffer[i];
|
|
32
26
|
}
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
// Checksum in header equals the sum we calculated
|
|
37
|
-
readSum === sum ||
|
|
38
|
-
|
|
39
|
-
// Checksum in header equals sum we calculated plus signed-to-unsigned delta
|
|
40
|
-
readSum === (sum - (signedBitSum << 1))
|
|
41
|
-
);
|
|
28
|
+
return readSum === sum;
|
|
42
29
|
};
|
|
43
30
|
|
|
44
31
|
/**
|