file-type 16.4.0 → 16.5.3
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 +3 -1
- package/core.js +12 -2
- package/package.json +5 -5
- package/readme.md +31 -0
- package/supported.js +2 -0
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
|
@@ -140,6 +140,7 @@ declare namespace core {
|
|
|
140
140
|
| 'chm'
|
|
141
141
|
| '3mf'
|
|
142
142
|
| 'zst'
|
|
143
|
+
| 'jxl'
|
|
143
144
|
| 'vcf';
|
|
144
145
|
|
|
145
146
|
type MimeType =
|
|
@@ -274,6 +275,7 @@ declare namespace core {
|
|
|
274
275
|
| 'model/stl'
|
|
275
276
|
| 'application/vnd.ms-htmlhelp'
|
|
276
277
|
| 'model/3mf'
|
|
278
|
+
| 'image/jxl'
|
|
277
279
|
| 'application/zstd';
|
|
278
280
|
|
|
279
281
|
interface FileTypeResult {
|
|
@@ -351,7 +353,7 @@ declare namespace core {
|
|
|
351
353
|
/**
|
|
352
354
|
Supported MIME types.
|
|
353
355
|
*/
|
|
354
|
-
const mimeTypes:
|
|
356
|
+
const mimeTypes: Set<core.MimeType>;
|
|
355
357
|
|
|
356
358
|
/**
|
|
357
359
|
Detect the file type of a readable stream.
|
package/core.js
CHANGED
|
@@ -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 (
|
|
@@ -1248,7 +1258,7 @@ async function _fromTokenizer(tokenizer) {
|
|
|
1248
1258
|
|
|
1249
1259
|
if (check([0x04, 0x00, 0x00, 0x00]) && buffer.length >= 16) { // Rough & quick check Pickle/ASAR
|
|
1250
1260
|
const jsonSize = buffer.readUInt32LE(12);
|
|
1251
|
-
if (jsonSize > 12 &&
|
|
1261
|
+
if (jsonSize > 12 && buffer.length >= jsonSize + 16) {
|
|
1252
1262
|
try {
|
|
1253
1263
|
const header = buffer.slice(16, jsonSize + 16).toString();
|
|
1254
1264
|
const json = JSON.parse(header);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.5.3",
|
|
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",
|
|
@@ -184,6 +184,7 @@
|
|
|
184
184
|
"chm",
|
|
185
185
|
"3mf",
|
|
186
186
|
"zst",
|
|
187
|
+
"jxl",
|
|
187
188
|
"vcf"
|
|
188
189
|
],
|
|
189
190
|
"devDependencies": {
|
|
@@ -196,9 +197,8 @@
|
|
|
196
197
|
},
|
|
197
198
|
"dependencies": {
|
|
198
199
|
"readable-web-to-node-stream": "^3.0.0",
|
|
199
|
-
"strtok3": "^6.
|
|
200
|
-
"token-types": "^
|
|
201
|
-
"typedarray-to-buffer": "^3.1.5"
|
|
200
|
+
"strtok3": "^6.2.4",
|
|
201
|
+
"token-types": "^4.1.1"
|
|
202
202
|
},
|
|
203
203
|
"xo": {
|
|
204
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
|
```
|
|
@@ -409,6 +439,7 @@ Returns a set of supported MIME types.
|
|
|
409
439
|
- [`stl`](https://en.wikipedia.org/wiki/STL_(file_format)) - Standard Tesselated Geometry File Format (ASCII only)
|
|
410
440
|
- [`chm`](https://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help) - Microsoft Compiled HTML Help
|
|
411
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
|
|
412
443
|
|
|
413
444
|
*Pull requests are welcome for additional commonly used file types.*
|
|
414
445
|
|
package/supported.js
CHANGED
|
@@ -138,6 +138,7 @@ module.exports = {
|
|
|
138
138
|
'chm',
|
|
139
139
|
'3mf',
|
|
140
140
|
'zst',
|
|
141
|
+
'jxl',
|
|
141
142
|
'vcf'
|
|
142
143
|
],
|
|
143
144
|
mimeTypes: [
|
|
@@ -272,6 +273,7 @@ module.exports = {
|
|
|
272
273
|
'model/stl',
|
|
273
274
|
'application/vnd.ms-htmlhelp',
|
|
274
275
|
'model/3mf',
|
|
276
|
+
'image/jxl',
|
|
275
277
|
'application/zstd'
|
|
276
278
|
]
|
|
277
279
|
};
|