file-type 16.3.0 → 16.5.2
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/browser.js +11 -12
- package/core.d.ts +8 -2
- package/core.js +70 -45
- package/package.json +8 -6
- package/readme.md +33 -0
- package/supported.js +7 -1
package/browser.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const {ReadableWebToNodeStream} = require('readable-web-to-node-stream');
|
|
3
|
-
const toBuffer = require('typedarray-to-buffer');
|
|
4
3
|
const core = require('./core');
|
|
5
4
|
|
|
6
5
|
async function fromStream(stream) {
|
|
@@ -11,25 +10,25 @@ async function fromStream(stream) {
|
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
async function fromBlob(blob) {
|
|
14
|
-
const buffer = await
|
|
15
|
-
return core.fromBuffer(buffer);
|
|
13
|
+
const buffer = await blobToArrayBuffer(blob);
|
|
14
|
+
return core.fromBuffer(Buffer.from(buffer));
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
|
-
Convert
|
|
18
|
+
Convert Blobs to ArrayBuffer.
|
|
20
19
|
@param {Blob} blob - Web API Blob.
|
|
21
|
-
@returns {Promise<
|
|
20
|
+
@returns {Promise<ArrayBuffer>}
|
|
22
21
|
*/
|
|
23
|
-
function
|
|
22
|
+
function blobToArrayBuffer(blob) {
|
|
23
|
+
if (blob.arrayBuffer) {
|
|
24
|
+
return blob.arrayBuffer();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// TODO: Remove when stop supporting older environments
|
|
24
28
|
return new Promise((resolve, reject) => {
|
|
25
29
|
const fileReader = new FileReader();
|
|
26
30
|
fileReader.addEventListener('loadend', event => {
|
|
27
|
-
|
|
28
|
-
if (data instanceof ArrayBuffer) {
|
|
29
|
-
data = toBuffer(new Uint8Array(event.target.result));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
resolve(data);
|
|
31
|
+
resolve(event.target.result);
|
|
33
32
|
});
|
|
34
33
|
|
|
35
34
|
fileReader.addEventListener('error', event => {
|
package/core.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare namespace core {
|
|
|
10
10
|
| 'gif'
|
|
11
11
|
| 'webp'
|
|
12
12
|
| 'flif'
|
|
13
|
+
| 'xcf'
|
|
13
14
|
| 'cr2'
|
|
14
15
|
| 'cr3'
|
|
15
16
|
| 'orf'
|
|
@@ -138,7 +139,9 @@ declare namespace core {
|
|
|
138
139
|
| 'stl'
|
|
139
140
|
| 'chm'
|
|
140
141
|
| '3mf'
|
|
141
|
-
| 'zst'
|
|
142
|
+
| 'zst'
|
|
143
|
+
| 'jxl'
|
|
144
|
+
| 'vcf';
|
|
142
145
|
|
|
143
146
|
type MimeType =
|
|
144
147
|
| 'image/jpeg'
|
|
@@ -146,6 +149,7 @@ declare namespace core {
|
|
|
146
149
|
| 'image/gif'
|
|
147
150
|
| 'image/webp'
|
|
148
151
|
| 'image/flif'
|
|
152
|
+
| 'image/x-xcf'
|
|
149
153
|
| 'image/x-canon-cr2'
|
|
150
154
|
| 'image/x-canon-cr3'
|
|
151
155
|
| 'image/tiff'
|
|
@@ -238,6 +242,7 @@ declare namespace core {
|
|
|
238
242
|
| 'application/dicom'
|
|
239
243
|
| 'audio/x-musepack'
|
|
240
244
|
| 'text/calendar'
|
|
245
|
+
| 'text/vcard'
|
|
241
246
|
| 'model/gltf-binary'
|
|
242
247
|
| 'application/vnd.tcpdump.pcap'
|
|
243
248
|
| 'audio/x-dsf' // Non-standard
|
|
@@ -270,6 +275,7 @@ declare namespace core {
|
|
|
270
275
|
| 'model/stl'
|
|
271
276
|
| 'application/vnd.ms-htmlhelp'
|
|
272
277
|
| 'model/3mf'
|
|
278
|
+
| 'image/jxl'
|
|
273
279
|
| 'application/zstd';
|
|
274
280
|
|
|
275
281
|
interface FileTypeResult {
|
|
@@ -347,7 +353,7 @@ declare namespace core {
|
|
|
347
353
|
/**
|
|
348
354
|
Supported MIME types.
|
|
349
355
|
*/
|
|
350
|
-
const mimeTypes:
|
|
356
|
+
const mimeTypes: Set<core.MimeType>;
|
|
351
357
|
|
|
352
358
|
/**
|
|
353
359
|
Detect the file type of a readable stream.
|
package/core.js
CHANGED
|
@@ -911,13 +911,6 @@ async function _fromTokenizer(tokenizer) {
|
|
|
911
911
|
};
|
|
912
912
|
}
|
|
913
913
|
|
|
914
|
-
if (checkString('BEGIN:')) {
|
|
915
|
-
return {
|
|
916
|
-
ext: 'ics',
|
|
917
|
-
mime: 'text/calendar'
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
|
|
921
914
|
if (check([0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C])) {
|
|
922
915
|
return {
|
|
923
916
|
ext: '7z',
|
|
@@ -1051,6 +1044,13 @@ async function _fromTokenizer(tokenizer) {
|
|
|
1051
1044
|
};
|
|
1052
1045
|
}
|
|
1053
1046
|
|
|
1047
|
+
if (checkString('gimp xcf ')) {
|
|
1048
|
+
return {
|
|
1049
|
+
ext: 'xcf',
|
|
1050
|
+
mime: 'image/x-xcf'
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
1054
|
// -- 12-byte signatures --
|
|
1055
1055
|
|
|
1056
1056
|
if (check([0x49, 0x49, 0x55, 0x00, 0x18, 0x00, 0x00, 0x00, 0x88, 0xE7, 0x74, 0xD8])) {
|
|
@@ -1067,7 +1067,7 @@ async function _fromTokenizer(tokenizer) {
|
|
|
1067
1067
|
await tokenizer.readBuffer(guid);
|
|
1068
1068
|
return {
|
|
1069
1069
|
id: guid,
|
|
1070
|
-
size: await tokenizer.readToken(Token.UINT64_LE)
|
|
1070
|
+
size: Number(await tokenizer.readToken(Token.UINT64_LE))
|
|
1071
1071
|
};
|
|
1072
1072
|
}
|
|
1073
1073
|
|
|
@@ -1162,6 +1162,16 @@ async function _fromTokenizer(tokenizer) {
|
|
|
1162
1162
|
}
|
|
1163
1163
|
}
|
|
1164
1164
|
|
|
1165
|
+
if (
|
|
1166
|
+
check([0xFF, 0x0A]) ||
|
|
1167
|
+
check([0x00, 0x00, 0x00, 0x0C, 0x4A, 0x58, 0x4C, 0x20, 0x0D, 0x0A, 0x87, 0x0A])
|
|
1168
|
+
) {
|
|
1169
|
+
return {
|
|
1170
|
+
ext: 'jxl',
|
|
1171
|
+
mime: 'image/jxl'
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1165
1175
|
// -- Unsafe signatures --
|
|
1166
1176
|
|
|
1167
1177
|
if (
|
|
@@ -1206,6 +1216,24 @@ async function _fromTokenizer(tokenizer) {
|
|
|
1206
1216
|
// Increase sample size from 12 to 256.
|
|
1207
1217
|
await tokenizer.peekBuffer(buffer, {length: Math.min(256, tokenizer.fileInfo.size), mayBeLess: true});
|
|
1208
1218
|
|
|
1219
|
+
// -- 15-byte signatures --
|
|
1220
|
+
|
|
1221
|
+
if (checkString('BEGIN:')) {
|
|
1222
|
+
if (checkString('VCARD', {offset: 6})) {
|
|
1223
|
+
return {
|
|
1224
|
+
ext: 'vcf',
|
|
1225
|
+
mime: 'text/vcard'
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
if (checkString('VCALENDAR', {offset: 6})) {
|
|
1230
|
+
return {
|
|
1231
|
+
ext: 'ics',
|
|
1232
|
+
mime: 'text/calendar'
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1209
1237
|
// `raf` is here just to keep all the raw image detectors together.
|
|
1210
1238
|
if (checkString('FUJIFILMCCD-RAW')) {
|
|
1211
1239
|
return {
|
|
@@ -1230,7 +1258,7 @@ async function _fromTokenizer(tokenizer) {
|
|
|
1230
1258
|
|
|
1231
1259
|
if (check([0x04, 0x00, 0x00, 0x00]) && buffer.length >= 16) { // Rough & quick check Pickle/ASAR
|
|
1232
1260
|
const jsonSize = buffer.readUInt32LE(12);
|
|
1233
|
-
if (jsonSize > 12 &&
|
|
1261
|
+
if (jsonSize > 12 && buffer.length >= jsonSize + 16) {
|
|
1234
1262
|
try {
|
|
1235
1263
|
const header = buffer.slice(16, jsonSize + 16).toString();
|
|
1236
1264
|
const json = JSON.parse(header);
|
|
@@ -1341,50 +1369,47 @@ async function _fromTokenizer(tokenizer) {
|
|
|
1341
1369
|
};
|
|
1342
1370
|
}
|
|
1343
1371
|
|
|
1344
|
-
// Check
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
if (check([
|
|
1349
|
-
// Check for (ADTS) MPEG-2
|
|
1350
|
-
if (check([0x08], {offset: start + 1, mask: [0x08]})) {
|
|
1351
|
-
return {
|
|
1352
|
-
ext: 'aac',
|
|
1353
|
-
mime: 'audio/aac'
|
|
1354
|
-
};
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
// Must be (ADTS) MPEG-4
|
|
1372
|
+
// Check MPEG 1 or 2 Layer 3 header, or 'layer 0' for ADTS (MPEG sync-word 0xFFE)
|
|
1373
|
+
if (buffer.length >= 2 && check([0xFF, 0xE0], {offset: 0, mask: [0xFF, 0xE0]})) {
|
|
1374
|
+
if (check([0x10], {offset: 1, mask: [0x16]})) {
|
|
1375
|
+
// Check for (ADTS) MPEG-2
|
|
1376
|
+
if (check([0x08], {offset: 1, mask: [0x08]})) {
|
|
1358
1377
|
return {
|
|
1359
1378
|
ext: 'aac',
|
|
1360
1379
|
mime: 'audio/aac'
|
|
1361
1380
|
};
|
|
1362
1381
|
}
|
|
1363
1382
|
|
|
1364
|
-
//
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
};
|
|
1371
|
-
}
|
|
1383
|
+
// Must be (ADTS) MPEG-4
|
|
1384
|
+
return {
|
|
1385
|
+
ext: 'aac',
|
|
1386
|
+
mime: 'audio/aac'
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1372
1389
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
}
|
|
1390
|
+
// MPEG 1 or 2 Layer 3 header
|
|
1391
|
+
// Check for MPEG layer 3
|
|
1392
|
+
if (check([0x02], {offset: 1, mask: [0x06]})) {
|
|
1393
|
+
return {
|
|
1394
|
+
ext: 'mp3',
|
|
1395
|
+
mime: 'audio/mpeg'
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1380
1398
|
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1399
|
+
// Check for MPEG layer 2
|
|
1400
|
+
if (check([0x04], {offset: 1, mask: [0x06]})) {
|
|
1401
|
+
return {
|
|
1402
|
+
ext: 'mp2',
|
|
1403
|
+
mime: 'audio/mpeg'
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
// Check for MPEG layer 1
|
|
1408
|
+
if (check([0x06], {offset: 1, mask: [0x06]})) {
|
|
1409
|
+
return {
|
|
1410
|
+
ext: 'mp1',
|
|
1411
|
+
mime: 'audio/mpeg'
|
|
1412
|
+
};
|
|
1388
1413
|
}
|
|
1389
1414
|
}
|
|
1390
1415
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.5.2",
|
|
4
4
|
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://sindresorhus.com"
|
|
12
12
|
},
|
|
13
13
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
14
|
+
"node": ">=10"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"ava": "ava --serial --verbose",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"gif",
|
|
55
55
|
"webp",
|
|
56
56
|
"flif",
|
|
57
|
+
"xcf",
|
|
57
58
|
"cr2",
|
|
58
59
|
"cr3",
|
|
59
60
|
"orf",
|
|
@@ -182,7 +183,9 @@
|
|
|
182
183
|
"stl",
|
|
183
184
|
"chm",
|
|
184
185
|
"3mf",
|
|
185
|
-
"zst"
|
|
186
|
+
"zst",
|
|
187
|
+
"jxl",
|
|
188
|
+
"vcf"
|
|
186
189
|
],
|
|
187
190
|
"devDependencies": {
|
|
188
191
|
"@types/node": "^13.1.4",
|
|
@@ -194,9 +197,8 @@
|
|
|
194
197
|
},
|
|
195
198
|
"dependencies": {
|
|
196
199
|
"readable-web-to-node-stream": "^3.0.0",
|
|
197
|
-
"strtok3": "
|
|
198
|
-
"token-types": "^
|
|
199
|
-
"typedarray-to-buffer": "^3.1.5"
|
|
200
|
+
"strtok3": "6.1.3",
|
|
201
|
+
"token-types": "^3.0.0"
|
|
200
202
|
},
|
|
201
203
|
"xo": {
|
|
202
204
|
"envs": [
|
package/readme.md
CHANGED
|
@@ -6,6 +6,36 @@ The file type is detected by checking the [magic number](https://en.wikipedia.or
|
|
|
6
6
|
|
|
7
7
|
This package is for detecting binary-based file formats, not text-based formats like `.txt`, `.csv`, `.svg`, etc.
|
|
8
8
|
|
|
9
|
+
<br>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<div align="center">
|
|
14
|
+
<p>
|
|
15
|
+
<p>
|
|
16
|
+
<sup>
|
|
17
|
+
<a href="https://github.com/sponsors/sindresorhus">My open source work is supported by the community</a>
|
|
18
|
+
</sup>
|
|
19
|
+
</p>
|
|
20
|
+
<sup>Special thanks to:</sup>
|
|
21
|
+
<br>
|
|
22
|
+
<br>
|
|
23
|
+
<a href="https://bit.io/?utm_campaign=github_repo&utm_medium=referral&utm_content=file-type&utm_source=github">
|
|
24
|
+
<div>
|
|
25
|
+
<img src="https://sindresorhus.com/assets/thanks/bitio-logo.svg" width="190" alt="bit.io">
|
|
26
|
+
</div>
|
|
27
|
+
<b>Instant, shareable cloud PostgreSQL database</b>
|
|
28
|
+
<div>
|
|
29
|
+
<sup>Import any dataset in seconds, share with anyone with a click, try without signing up</sup>
|
|
30
|
+
</div>
|
|
31
|
+
</a>
|
|
32
|
+
</p>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
<br>
|
|
38
|
+
|
|
9
39
|
## Install
|
|
10
40
|
|
|
11
41
|
```
|
|
@@ -278,6 +308,7 @@ Returns a set of supported MIME types.
|
|
|
278
308
|
- [`gif`](https://en.wikipedia.org/wiki/GIF) - Graphics Interchange Format
|
|
279
309
|
- [`webp`](https://en.wikipedia.org/wiki/WebP) - Web Picture format
|
|
280
310
|
- [`flif`](https://en.wikipedia.org/wiki/Free_Lossless_Image_Format) - Free Lossless Image Format
|
|
311
|
+
- [`xcf`](https://en.wikipedia.org/wiki/XCF_(file_format)) - eXperimental Computing Facility
|
|
281
312
|
- [`cr2`](https://fileinfo.com/extension/cr2) - Canon Raw image file (v2)
|
|
282
313
|
- [`cr3`](https://fileinfo.com/extension/cr3) - Canon Raw image file (v3)
|
|
283
314
|
- [`orf`](https://en.wikipedia.org/wiki/ORF_format) - Olympus Raw image file
|
|
@@ -373,6 +404,7 @@ Returns a set of supported MIME types.
|
|
|
373
404
|
- [`dcm`](https://en.wikipedia.org/wiki/DICOM#Data_format) - DICOM Image File
|
|
374
405
|
- [`mpc`](https://en.wikipedia.org/wiki/Musepack) - Musepack (SV7 & SV8)
|
|
375
406
|
- [`ics`](https://en.wikipedia.org/wiki/ICalendar#Data_format) - iCalendar
|
|
407
|
+
- [`vcf`](https://en.wikipedia.org/wiki/VCard) - vCard
|
|
376
408
|
- [`glb`](https://github.com/KhronosGroup/glTF) - GL Transmission Format
|
|
377
409
|
- [`pcap`](https://wiki.wireshark.org/Development/LibpcapFileFormat) - Libpcap File Format
|
|
378
410
|
- [`dsf`](https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf) - Sony DSD Stream File (DSF)
|
|
@@ -407,6 +439,7 @@ Returns a set of supported MIME types.
|
|
|
407
439
|
- [`stl`](https://en.wikipedia.org/wiki/STL_(file_format)) - Standard Tesselated Geometry File Format (ASCII only)
|
|
408
440
|
- [`chm`](https://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help) - Microsoft Compiled HTML Help
|
|
409
441
|
- [`3mf`](https://en.wikipedia.org/wiki/3D_Manufacturing_Format) - 3D Manufacturing Format
|
|
442
|
+
- [`jxl`](https://en.wikipedia.org/wiki/JPEG_XL) - JPEG XL image format
|
|
410
443
|
|
|
411
444
|
*Pull requests are welcome for additional commonly used file types.*
|
|
412
445
|
|
package/supported.js
CHANGED
|
@@ -8,6 +8,7 @@ module.exports = {
|
|
|
8
8
|
'gif',
|
|
9
9
|
'webp',
|
|
10
10
|
'flif',
|
|
11
|
+
'xcf',
|
|
11
12
|
'cr2',
|
|
12
13
|
'cr3',
|
|
13
14
|
'orf',
|
|
@@ -136,7 +137,9 @@ module.exports = {
|
|
|
136
137
|
'stl',
|
|
137
138
|
'chm',
|
|
138
139
|
'3mf',
|
|
139
|
-
'zst'
|
|
140
|
+
'zst',
|
|
141
|
+
'jxl',
|
|
142
|
+
'vcf'
|
|
140
143
|
],
|
|
141
144
|
mimeTypes: [
|
|
142
145
|
'image/jpeg',
|
|
@@ -144,6 +147,7 @@ module.exports = {
|
|
|
144
147
|
'image/gif',
|
|
145
148
|
'image/webp',
|
|
146
149
|
'image/flif',
|
|
150
|
+
'image/x-xcf',
|
|
147
151
|
'image/x-canon-cr2',
|
|
148
152
|
'image/x-canon-cr3',
|
|
149
153
|
'image/tiff',
|
|
@@ -236,6 +240,7 @@ module.exports = {
|
|
|
236
240
|
'application/dicom',
|
|
237
241
|
'audio/x-musepack',
|
|
238
242
|
'text/calendar',
|
|
243
|
+
'text/vcard',
|
|
239
244
|
'model/gltf-binary',
|
|
240
245
|
'application/vnd.tcpdump.pcap',
|
|
241
246
|
'audio/x-dsf', // Non-standard
|
|
@@ -268,6 +273,7 @@ module.exports = {
|
|
|
268
273
|
'model/stl',
|
|
269
274
|
'application/vnd.ms-htmlhelp',
|
|
270
275
|
'model/3mf',
|
|
276
|
+
'image/jxl',
|
|
271
277
|
'application/zstd'
|
|
272
278
|
]
|
|
273
279
|
};
|