file-type 16.4.0 → 16.5.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/browser.js +11 -12
- package/core.d.ts +2 -0
- package/core.js +11 -1
- package/package.json +3 -3
- package/readme.md +1 -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 {
|
package/core.js
CHANGED
|
@@ -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.0",
|
|
4
4
|
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -184,6 +184,7 @@
|
|
|
184
184
|
"chm",
|
|
185
185
|
"3mf",
|
|
186
186
|
"zst",
|
|
187
|
+
"jxl",
|
|
187
188
|
"vcf"
|
|
188
189
|
],
|
|
189
190
|
"devDependencies": {
|
|
@@ -197,8 +198,7 @@
|
|
|
197
198
|
"dependencies": {
|
|
198
199
|
"readable-web-to-node-stream": "^3.0.0",
|
|
199
200
|
"strtok3": "^6.0.3",
|
|
200
|
-
"token-types": "^2.0.0"
|
|
201
|
-
"typedarray-to-buffer": "^3.1.5"
|
|
201
|
+
"token-types": "^2.0.0"
|
|
202
202
|
},
|
|
203
203
|
"xo": {
|
|
204
204
|
"envs": [
|
package/readme.md
CHANGED
|
@@ -409,6 +409,7 @@ Returns a set of supported MIME types.
|
|
|
409
409
|
- [`stl`](https://en.wikipedia.org/wiki/STL_(file_format)) - Standard Tesselated Geometry File Format (ASCII only)
|
|
410
410
|
- [`chm`](https://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help) - Microsoft Compiled HTML Help
|
|
411
411
|
- [`3mf`](https://en.wikipedia.org/wiki/3D_Manufacturing_Format) - 3D Manufacturing Format
|
|
412
|
+
- [`jxl`](https://en.wikipedia.org/wiki/JPEG_XL) - JPEG XL image format
|
|
412
413
|
|
|
413
414
|
*Pull requests are welcome for additional commonly used file types.*
|
|
414
415
|
|
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
|
};
|