file-type 21.2.0 → 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 +25 -5
- package/package.json +1 -1
- package/readme.md +1 -15
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',
|
|
@@ -1064,10 +1069,25 @@ export class FileTypeParser {
|
|
|
1064
1069
|
}
|
|
1065
1070
|
|
|
1066
1071
|
if (this.check([0xCA, 0xFE, 0xBA, 0xBE])) {
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
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
|
+
}
|
|
1071
1091
|
}
|
|
1072
1092
|
|
|
1073
1093
|
if (this.checkString('.RMF')) {
|
package/package.json
CHANGED
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
|