file-type 17.1.2 → 17.1.5
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 +2 -2
- package/core.js +34 -23
- package/package.json +2 -2
- package/readme.md +2 -2
package/core.d.ts
CHANGED
|
@@ -364,7 +364,7 @@ export interface StreamOptions {
|
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
/**
|
|
367
|
-
Returns a `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `
|
|
367
|
+
Returns a `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `fileTypeFromFile()`.
|
|
368
368
|
|
|
369
369
|
This method can be handy to put in between a stream, but it comes with a price.
|
|
370
370
|
Internally `stream()` builds up a buffer of `sampleSize` bytes, used as a sample, to determine the file type.
|
|
@@ -375,7 +375,7 @@ A smaller sample size will result in lower probability of the best file type det
|
|
|
375
375
|
**Note:** Requires Node.js 14 or later.
|
|
376
376
|
|
|
377
377
|
@param readableStream - A [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable) containing a file to examine.
|
|
378
|
-
@returns A `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `
|
|
378
|
+
@returns A `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `fileTypeFromFile()`.
|
|
379
379
|
|
|
380
380
|
@example
|
|
381
381
|
```
|
package/core.js
CHANGED
|
@@ -146,6 +146,12 @@ class FileTypeParser {
|
|
|
146
146
|
|
|
147
147
|
// -- 3-byte signatures --
|
|
148
148
|
|
|
149
|
+
if (this.check([0xEF, 0xBB, 0xBF])) { // UTF-8-BOM
|
|
150
|
+
// Strip off UTF-8-BOM
|
|
151
|
+
this.tokenizer.ignore(3);
|
|
152
|
+
return this.parse(tokenizer);
|
|
153
|
+
}
|
|
154
|
+
|
|
149
155
|
if (this.check([0x47, 0x49, 0x46])) {
|
|
150
156
|
return {
|
|
151
157
|
ext: 'gif',
|
|
@@ -654,7 +660,7 @@ class FileTypeParser {
|
|
|
654
660
|
let ic = 0; // 0 = A, 1 = B, 2 = C, 3
|
|
655
661
|
// = D
|
|
656
662
|
|
|
657
|
-
while ((msb & mask) === 0) {
|
|
663
|
+
while ((msb & mask) === 0 && mask !== 0) {
|
|
658
664
|
++ic;
|
|
659
665
|
mask >>= 1;
|
|
660
666
|
}
|
|
@@ -675,7 +681,7 @@ class FileTypeParser {
|
|
|
675
681
|
};
|
|
676
682
|
}
|
|
677
683
|
|
|
678
|
-
async function readChildren(
|
|
684
|
+
async function readChildren(children) {
|
|
679
685
|
while (children > 0) {
|
|
680
686
|
const element = await readElement();
|
|
681
687
|
if (element.id === 0x42_82) {
|
|
@@ -689,7 +695,7 @@ class FileTypeParser {
|
|
|
689
695
|
}
|
|
690
696
|
|
|
691
697
|
const re = await readElement();
|
|
692
|
-
const docType = await readChildren(
|
|
698
|
+
const docType = await readChildren(re.len);
|
|
693
699
|
|
|
694
700
|
switch (docType) {
|
|
695
701
|
case 'webm':
|
|
@@ -1016,13 +1022,6 @@ class FileTypeParser {
|
|
|
1016
1022
|
};
|
|
1017
1023
|
}
|
|
1018
1024
|
|
|
1019
|
-
if (this.check([0xEF, 0xBB, 0xBF]) && this.checkString('<?xml', {offset: 3})) { // UTF-8-BOM
|
|
1020
|
-
return {
|
|
1021
|
-
ext: 'xml',
|
|
1022
|
-
mime: 'application/xml',
|
|
1023
|
-
};
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
1025
|
// -- 9-byte signatures --
|
|
1027
1026
|
|
|
1028
1027
|
if (this.check([0x49, 0x49, 0x52, 0x4F, 0x08, 0x00, 0x00, 0x00, 0x18])) {
|
|
@@ -1160,14 +1159,15 @@ class FileTypeParser {
|
|
|
1160
1159
|
};
|
|
1161
1160
|
}
|
|
1162
1161
|
|
|
1163
|
-
if (
|
|
1164
|
-
this.check([
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1162
|
+
if (this.check([0xFE, 0xFF])) { // UTF-16-BOM-LE
|
|
1163
|
+
if (this.check([0, 60, 0, 63, 0, 120, 0, 109, 0, 108], {offset: 2})) {
|
|
1164
|
+
return {
|
|
1165
|
+
ext: 'xml',
|
|
1166
|
+
mime: 'application/xml',
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
return undefined; // Some unknown text based format
|
|
1171
1171
|
}
|
|
1172
1172
|
|
|
1173
1173
|
// -- Unsafe signatures --
|
|
@@ -1361,11 +1361,22 @@ class FileTypeParser {
|
|
|
1361
1361
|
};
|
|
1362
1362
|
}
|
|
1363
1363
|
|
|
1364
|
-
if (this.check([0xFF, 0xFE
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1364
|
+
if (this.check([0xFF, 0xFE])) { // UTF-16-BOM-BE
|
|
1365
|
+
if (this.check([60, 0, 63, 0, 120, 0, 109, 0, 108, 0], {offset: 2})) {
|
|
1366
|
+
return {
|
|
1367
|
+
ext: 'xml',
|
|
1368
|
+
mime: 'application/xml',
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
if (this.check([0xFF, 0x0E, 0x53, 0x00, 0x6B, 0x00, 0x65, 0x00, 0x74, 0x00, 0x63, 0x00, 0x68, 0x00, 0x55, 0x00, 0x70, 0x00, 0x20, 0x00, 0x4D, 0x00, 0x6F, 0x00, 0x64, 0x00, 0x65, 0x00, 0x6C, 0x00], {offset: 2})) {
|
|
1373
|
+
return {
|
|
1374
|
+
ext: 'skp',
|
|
1375
|
+
mime: 'application/vnd.sketchup.skp',
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
return undefined; // Some text based format
|
|
1369
1380
|
}
|
|
1370
1381
|
|
|
1371
1382
|
if (this.checkString('-----BEGIN PGP MESSAGE-----')) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "17.1.
|
|
3
|
+
"version": "17.1.5",
|
|
4
4
|
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -197,7 +197,7 @@
|
|
|
197
197
|
],
|
|
198
198
|
"dependencies": {
|
|
199
199
|
"readable-web-to-node-stream": "^3.0.2",
|
|
200
|
-
"strtok3": "^7.0.0-alpha.
|
|
200
|
+
"strtok3": "^7.0.0-alpha.9",
|
|
201
201
|
"token-types": "^5.0.0-alpha.2"
|
|
202
202
|
},
|
|
203
203
|
"devDependencies": {
|
package/readme.md
CHANGED
|
@@ -141,7 +141,7 @@ Detect the file type of a `Buffer`, `Uint8Array`, or `ArrayBuffer`.
|
|
|
141
141
|
|
|
142
142
|
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.
|
|
143
143
|
|
|
144
|
-
If file access is available, it is recommended to use `
|
|
144
|
+
If file access is available, it is recommended to use `fileTypeFromFile()` instead.
|
|
145
145
|
|
|
146
146
|
Returns a `Promise` for an object with the detected file type and MIME type:
|
|
147
147
|
|
|
@@ -282,7 +282,7 @@ A file source implementing the [tokenizer interface](https://github.com/Borewit/
|
|
|
282
282
|
|
|
283
283
|
### fileTypeStream(readableStream, options?)
|
|
284
284
|
|
|
285
|
-
Returns a `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `
|
|
285
|
+
Returns a `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `fileTypeFromFile()`.
|
|
286
286
|
|
|
287
287
|
This method can be handy to put in between a stream, but it comes with a price.
|
|
288
288
|
Internally `stream()` builds up a buffer of `sampleSize` bytes, used as a sample, to determine the file type.
|