file-type 21.1.1 → 21.3.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 +44 -5
- package/package.json +3 -1
- package/readme.md +3 -15
- package/supported.js +4 -0
package/core.js
CHANGED
|
@@ -951,7 +951,12 @@ export class FileTypeParser {
|
|
|
951
951
|
};
|
|
952
952
|
}
|
|
953
953
|
|
|
954
|
-
if (
|
|
954
|
+
if (
|
|
955
|
+
this.check([0xFE, 0xED, 0xFA, 0xCE]) // 32-bit, big-endian
|
|
956
|
+
|| this.check([0xFE, 0xED, 0xFA, 0xCF]) // 64-bit, big-endian
|
|
957
|
+
|| this.check([0xCE, 0xFA, 0xED, 0xFE]) // 32-bit, little-endian
|
|
958
|
+
|| this.check([0xCF, 0xFA, 0xED, 0xFE]) // 64-bit, little-endian
|
|
959
|
+
) {
|
|
955
960
|
return {
|
|
956
961
|
ext: 'macho',
|
|
957
962
|
mime: 'application/x-mach-binary',
|
|
@@ -972,6 +977,14 @@ export class FileTypeParser {
|
|
|
972
977
|
};
|
|
973
978
|
}
|
|
974
979
|
|
|
980
|
+
// SPSS Statistical Data File
|
|
981
|
+
if (this.checkString('$FL2') || this.checkString('$FL3')) {
|
|
982
|
+
return {
|
|
983
|
+
ext: 'sav',
|
|
984
|
+
mime: 'application/x-spss-sav',
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
|
|
975
988
|
// -- 5-byte signatures --
|
|
976
989
|
|
|
977
990
|
if (this.check([0x4F, 0x54, 0x54, 0x4F, 0x00])) {
|
|
@@ -1056,10 +1069,25 @@ export class FileTypeParser {
|
|
|
1056
1069
|
}
|
|
1057
1070
|
|
|
1058
1071
|
if (this.check([0xCA, 0xFE, 0xBA, 0xBE])) {
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1072
|
+
// Java bytecode and Mach-O universal binaries have the same magic number.
|
|
1073
|
+
// We disambiguate based on the next 4 bytes, as done by `file`.
|
|
1074
|
+
// See https://github.com/file/file/blob/master/magic/Magdir/cafebabe
|
|
1075
|
+
const machOArchitectureCount = Token.UINT32_BE.get(this.buffer, 4);
|
|
1076
|
+
const javaClassFileMajorVersion = Token.UINT16_BE.get(this.buffer, 6);
|
|
1077
|
+
|
|
1078
|
+
if (machOArchitectureCount > 0 && machOArchitectureCount <= 30) {
|
|
1079
|
+
return {
|
|
1080
|
+
ext: 'macho',
|
|
1081
|
+
mime: 'application/x-mach-binary',
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
if (javaClassFileMajorVersion > 30) {
|
|
1086
|
+
return {
|
|
1087
|
+
ext: 'class',
|
|
1088
|
+
mime: 'application/java-vm',
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1063
1091
|
}
|
|
1064
1092
|
|
|
1065
1093
|
if (this.checkString('.RMF')) {
|
|
@@ -1673,6 +1701,17 @@ export class FileTypeParser {
|
|
|
1673
1701
|
};
|
|
1674
1702
|
}
|
|
1675
1703
|
|
|
1704
|
+
// -- 16-byte signatures --
|
|
1705
|
+
|
|
1706
|
+
// JMP files - check for both Little Endian and Big Endian signatures
|
|
1707
|
+
if (this.check([0xFF, 0xFF, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00])
|
|
1708
|
+
|| this.check([0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x01])) {
|
|
1709
|
+
return {
|
|
1710
|
+
ext: 'jmp',
|
|
1711
|
+
mime: 'application/x-jmp-data',
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1676
1715
|
// Increase sample size from 256 to 512
|
|
1677
1716
|
await tokenizer.peekBuffer(this.buffer, {length: Math.min(512, tokenizer.fileInfo.size), mayBeLess: true});
|
|
1678
1717
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.3.0",
|
|
4
4
|
"description": "Detect the file type of a file, stream, or data",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -241,7 +241,9 @@
|
|
|
241
241
|
"potm",
|
|
242
242
|
"pptm",
|
|
243
243
|
"jar",
|
|
244
|
+
"jmp",
|
|
244
245
|
"rm",
|
|
246
|
+
"sav",
|
|
245
247
|
"ppsm",
|
|
246
248
|
"ppsx",
|
|
247
249
|
"tar.gz",
|
package/readme.md
CHANGED
|
@@ -206,21 +206,6 @@ console.log(await fileTypeFromBlob(blob));
|
|
|
206
206
|
//=> {ext: 'txt', mime: 'text/plain'}
|
|
207
207
|
```
|
|
208
208
|
|
|
209
|
-
> [!WARNING]
|
|
210
|
-
> This method depends on [ReadableStreamBYOBReader](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader) which **requires Node.js ≥ 20**
|
|
211
|
-
> and [may not be available in all modern browsers](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader#browser_compatibility).
|
|
212
|
-
|
|
213
|
-
To work around this limitation, you can use an alternative approach to read and process the `Blob` without relying on streaming:
|
|
214
|
-
|
|
215
|
-
```js
|
|
216
|
-
import {fileTypeFromBuffer} from 'file-type';
|
|
217
|
-
|
|
218
|
-
async function readFromBlobWithoutStreaming(blob) {
|
|
219
|
-
const buffer = await blob.arrayBuffer();
|
|
220
|
-
return fileTypeFromBuffer(buffer);
|
|
221
|
-
}
|
|
222
|
-
```
|
|
223
|
-
|
|
224
209
|
#### blob
|
|
225
210
|
|
|
226
211
|
Type: [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
|
|
@@ -395,6 +380,7 @@ console.log(fileType);
|
|
|
395
380
|
### Available third-party file-type detectors
|
|
396
381
|
|
|
397
382
|
- [@file-type/av](https://github.com/Borewit/file-type-av): Improves detection of audio and video file formats, with accurate differentiation between the two
|
|
383
|
+
- [@file-type/pdf](https://github.com/Borewit/file-type-pdf): Detects PDF based file types, such as Adobe Illustrator
|
|
398
384
|
- [@file-type/xml](https://github.com/Borewit/file-type-xml): Detects common XML file types, such as GLM, KML, MusicXML, RSS, SVG, and XHTML
|
|
399
385
|
|
|
400
386
|
### Detector execution flow
|
|
@@ -533,6 +519,7 @@ abortController.abort(); // Abort file-type reading from the Blob stream.
|
|
|
533
519
|
- [`j2c`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
|
|
534
520
|
- [`jar`](https://en.wikipedia.org/wiki/JAR_(file_format)) - Java archive
|
|
535
521
|
- [`jls`](https://en.wikipedia.org/wiki/Lossless_JPEG#JPEG-LS) - Lossless/near-lossless compression standard for continuous-tone images
|
|
522
|
+
- [`jmp`](https://en.wikipedia.org/wiki/JMP_(statistical_software)) - JMP data file format by SAS Institute
|
|
536
523
|
- [`jp2`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
|
|
537
524
|
- [`jpg`](https://en.wikipedia.org/wiki/JPEG) - Joint Photographic Experts Group image
|
|
538
525
|
- [`jpm`](https://en.wikipedia.org/wiki/JPEG_2000) - JPEG 2000
|
|
@@ -604,6 +591,7 @@ abortController.abort(); // Abort file-type reading from the Blob stream.
|
|
|
604
591
|
- [`rtf`](https://en.wikipedia.org/wiki/Rich_Text_Format) - Rich Text Format
|
|
605
592
|
- [`rw2`](https://en.wikipedia.org/wiki/Raw_image_format) - Panasonic RAW image file
|
|
606
593
|
- [`s3m`](https://wiki.openmpt.org/Manual:_Module_formats#The_ScreamTracker_3_format_.28.s3m.29) - Audio module format: ScreamTracker 3
|
|
594
|
+
- [`sav`](https://en.wikipedia.org/wiki/SPSS) - SPSS Statistical Data File
|
|
607
595
|
- [`shp`](https://en.wikipedia.org/wiki/Shapefile) - Geospatial vector data format
|
|
608
596
|
- [`skp`](https://en.wikipedia.org/wiki/SketchUp) - SketchUp
|
|
609
597
|
- [`spx`](https://en.wikipedia.org/wiki/Ogg) - Audio file
|
package/supported.js
CHANGED
|
@@ -171,7 +171,9 @@ export const extensions = [
|
|
|
171
171
|
'potm',
|
|
172
172
|
'pptm',
|
|
173
173
|
'jar',
|
|
174
|
+
'jmp',
|
|
174
175
|
'rm',
|
|
176
|
+
'sav',
|
|
175
177
|
'ppsm',
|
|
176
178
|
'ppsx',
|
|
177
179
|
'tar.gz',
|
|
@@ -351,6 +353,8 @@ export const mimeTypes = [
|
|
|
351
353
|
'application/vnd.ms-powerpoint.presentation.macroenabled.12',
|
|
352
354
|
'application/java-archive',
|
|
353
355
|
'application/vnd.rn-realmedia',
|
|
356
|
+
'application/x-spss-sav',
|
|
354
357
|
'application/x-ms-regedit',
|
|
355
358
|
'application/x-ft-windows-registry-hive',
|
|
359
|
+
'application/x-jmp-data',
|
|
356
360
|
];
|