file-type 20.0.0 → 20.1.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.js +45 -43
- package/package.json +2 -2
- package/readme.md +7 -4
package/core.js
CHANGED
|
@@ -476,13 +476,6 @@ export class FileTypeParser {
|
|
|
476
476
|
};
|
|
477
477
|
}
|
|
478
478
|
|
|
479
|
-
if (this.checkString('WEBP', {offset: 8})) {
|
|
480
|
-
return {
|
|
481
|
-
ext: 'webp',
|
|
482
|
-
mime: 'image/webp',
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
|
|
486
479
|
// Musepack, SV8
|
|
487
480
|
if (this.checkString('MPCK')) {
|
|
488
481
|
return {
|
|
@@ -726,17 +719,19 @@ export class FileTypeParser {
|
|
|
726
719
|
|
|
727
720
|
if (this.checkString('%PDF')) {
|
|
728
721
|
try {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
722
|
+
const skipBytes = 1350;
|
|
723
|
+
if (skipBytes === await tokenizer.ignore(skipBytes)) {
|
|
724
|
+
const maxBufferSize = 10 * 1024 * 1024;
|
|
725
|
+
const buffer = new Uint8Array(Math.min(maxBufferSize, tokenizer.fileInfo.size - skipBytes));
|
|
726
|
+
await tokenizer.readBuffer(buffer, {mayBeLess: true});
|
|
727
|
+
|
|
728
|
+
// Check if this is an Adobe Illustrator file
|
|
729
|
+
if (includes(buffer, new TextEncoder().encode('AIPrivateData'))) {
|
|
730
|
+
return {
|
|
731
|
+
ext: 'ai',
|
|
732
|
+
mime: 'application/postscript',
|
|
733
|
+
};
|
|
734
|
+
}
|
|
740
735
|
}
|
|
741
736
|
} catch (error) {
|
|
742
737
|
// Swallow end of stream error if file is too small for the Adobe AI check
|
|
@@ -849,31 +844,6 @@ export class FileTypeParser {
|
|
|
849
844
|
}
|
|
850
845
|
}
|
|
851
846
|
|
|
852
|
-
// RIFF file format which might be AVI, WAV, QCP, etc
|
|
853
|
-
if (this.check([0x52, 0x49, 0x46, 0x46])) {
|
|
854
|
-
if (this.check([0x41, 0x56, 0x49], {offset: 8})) {
|
|
855
|
-
return {
|
|
856
|
-
ext: 'avi',
|
|
857
|
-
mime: 'video/vnd.avi',
|
|
858
|
-
};
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
if (this.check([0x57, 0x41, 0x56, 0x45], {offset: 8})) {
|
|
862
|
-
return {
|
|
863
|
-
ext: 'wav',
|
|
864
|
-
mime: 'audio/wav',
|
|
865
|
-
};
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
// QLCM, QCP file
|
|
869
|
-
if (this.check([0x51, 0x4C, 0x43, 0x4D], {offset: 8})) {
|
|
870
|
-
return {
|
|
871
|
-
ext: 'qcp',
|
|
872
|
-
mime: 'audio/qcelp',
|
|
873
|
-
};
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
|
|
877
847
|
if (this.checkString('SQLi')) {
|
|
878
848
|
return {
|
|
879
849
|
ext: 'sqlite',
|
|
@@ -1305,6 +1275,38 @@ export class FileTypeParser {
|
|
|
1305
1275
|
|
|
1306
1276
|
// -- 12-byte signatures --
|
|
1307
1277
|
|
|
1278
|
+
// RIFF file format which might be AVI, WAV, QCP, etc
|
|
1279
|
+
if (this.check([0x52, 0x49, 0x46, 0x46])) {
|
|
1280
|
+
if (this.checkString('WEBP', {offset: 8})) {
|
|
1281
|
+
return {
|
|
1282
|
+
ext: 'webp',
|
|
1283
|
+
mime: 'image/webp',
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
if (this.check([0x41, 0x56, 0x49], {offset: 8})) {
|
|
1288
|
+
return {
|
|
1289
|
+
ext: 'avi',
|
|
1290
|
+
mime: 'video/vnd.avi',
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
if (this.check([0x57, 0x41, 0x56, 0x45], {offset: 8})) {
|
|
1295
|
+
return {
|
|
1296
|
+
ext: 'wav',
|
|
1297
|
+
mime: 'audio/wav',
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
// QLCM, QCP file
|
|
1302
|
+
if (this.check([0x51, 0x4C, 0x43, 0x4D], {offset: 8})) {
|
|
1303
|
+
return {
|
|
1304
|
+
ext: 'qcp',
|
|
1305
|
+
mime: 'audio/qcelp',
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1308
1310
|
if (this.check([0x49, 0x49, 0x55, 0x00, 0x18, 0x00, 0x00, 0x00, 0x88, 0xE7, 0x74, 0xD8])) {
|
|
1309
1311
|
return {
|
|
1310
1312
|
ext: 'rw2',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.1.0",
|
|
4
4
|
"description": "Detect the file type of a file, stream, or data",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -238,7 +238,7 @@
|
|
|
238
238
|
],
|
|
239
239
|
"dependencies": {
|
|
240
240
|
"@tokenizer/inflate": "^0.2.6",
|
|
241
|
-
"strtok3": "^10.0
|
|
241
|
+
"strtok3": "^10.2.0",
|
|
242
242
|
"token-types": "^6.0.0",
|
|
243
243
|
"uint8array-extras": "^1.4.0"
|
|
244
244
|
},
|
package/readme.md
CHANGED
|
@@ -20,6 +20,8 @@ npm install file-type
|
|
|
20
20
|
|
|
21
21
|
If you use it with Webpack, you need the latest Webpack version and ensure you configure it correctly for ESM.
|
|
22
22
|
|
|
23
|
+
File type detection is based on binary signatures (magic numbers) and should be treated as a best-effort hint, not a guarantee.
|
|
24
|
+
|
|
23
25
|
## Usage
|
|
24
26
|
|
|
25
27
|
### Node.js
|
|
@@ -256,15 +258,16 @@ console.log(fileType);
|
|
|
256
258
|
Or use [`@tokenizer/s3`](https://github.com/Borewit/tokenizer-s3) to determine the file type of a file stored on [Amazon S3](https://aws.amazon.com/s3):
|
|
257
259
|
|
|
258
260
|
```js
|
|
259
|
-
import
|
|
260
|
-
import {
|
|
261
|
+
import {S3Client} from '@aws-sdk/client-s3';
|
|
262
|
+
import {makeChunkedTokenizerFromS3} from '@tokenizer/s3';
|
|
261
263
|
import {fileTypeFromTokenizer} from 'file-type';
|
|
262
264
|
|
|
263
265
|
// Initialize the S3 client
|
|
264
|
-
|
|
266
|
+
// Initialize S3 client
|
|
267
|
+
const s3 = new S3Client();
|
|
265
268
|
|
|
266
269
|
// Initialize the S3 tokenizer.
|
|
267
|
-
const s3Tokenizer = await
|
|
270
|
+
const s3Tokenizer = await makeChunkedTokenizerFromS3(s3, {
|
|
268
271
|
Bucket: 'affectlab',
|
|
269
272
|
Key: '1min_35sec.mp4'
|
|
270
273
|
});
|