file-type 12.3.0 → 12.4.2
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/index.d.ts +8 -4
- package/index.js +29 -15
- package/package.json +4 -2
- package/readme.md +18 -22
- package/supported.js +6 -2
package/index.d.ts
CHANGED
|
@@ -118,7 +118,9 @@ declare namespace fileType {
|
|
|
118
118
|
| 'ogm'
|
|
119
119
|
| 'oga'
|
|
120
120
|
| 'spx'
|
|
121
|
-
| 'ogx'
|
|
121
|
+
| 'ogx'
|
|
122
|
+
| 'arrow'
|
|
123
|
+
| 'shp';
|
|
122
124
|
|
|
123
125
|
type MimeType =
|
|
124
126
|
| 'image/jpeg'
|
|
@@ -194,6 +196,7 @@ declare namespace fileType {
|
|
|
194
196
|
| 'application/x-lzip'
|
|
195
197
|
| 'application/x-msi'
|
|
196
198
|
| 'application/x-mie'
|
|
199
|
+
| 'application/x-apache-arrow'
|
|
197
200
|
| 'application/mxf'
|
|
198
201
|
| 'video/mp2t'
|
|
199
202
|
| 'application/x-blender'
|
|
@@ -229,7 +232,8 @@ declare namespace fileType {
|
|
|
229
232
|
| 'image/x-panasonic-rw2'
|
|
230
233
|
| 'image/x-fujifilm-raf'
|
|
231
234
|
| 'video/x-m4v'
|
|
232
|
-
| 'video/3gpp2'
|
|
235
|
+
| 'video/3gpp2'
|
|
236
|
+
| 'application/x-esri-shape';
|
|
233
237
|
|
|
234
238
|
interface FileTypeResult {
|
|
235
239
|
/**
|
|
@@ -292,12 +296,12 @@ declare const fileType: {
|
|
|
292
296
|
/**
|
|
293
297
|
Supported file extensions.
|
|
294
298
|
*/
|
|
295
|
-
readonly extensions: fileType.FileType;
|
|
299
|
+
readonly extensions: readonly fileType.FileType[];
|
|
296
300
|
|
|
297
301
|
/**
|
|
298
302
|
Supported MIME types.
|
|
299
303
|
*/
|
|
300
|
-
readonly mimeTypes: fileType.MimeType;
|
|
304
|
+
readonly mimeTypes: readonly fileType.MimeType[];
|
|
301
305
|
|
|
302
306
|
/**
|
|
303
307
|
Detect the file type of a readable stream.
|
package/index.js
CHANGED
|
@@ -119,9 +119,9 @@ const fileType = input => {
|
|
|
119
119
|
|
|
120
120
|
if (
|
|
121
121
|
check([0x49, 0x49, 0x2A, 0x00]) &&
|
|
122
|
-
(check([0x10, 0xFB, 0x86, 0x01], {offset: 4}) ||
|
|
123
|
-
|
|
124
|
-
check([
|
|
122
|
+
(check([0x10, 0xFB, 0x86, 0x01], {offset: 4}) || check([0x08, 0x00, 0x00, 0x00], {offset: 4})) &&
|
|
123
|
+
// This pattern differentiates ARW from other TIFF-ish file types:
|
|
124
|
+
check([0x00, 0xFE, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x01], {offset: 9})
|
|
125
125
|
) {
|
|
126
126
|
return {
|
|
127
127
|
ext: 'arw',
|
|
@@ -364,12 +364,12 @@ const fileType = input => {
|
|
|
364
364
|
// `ftyp` box must contain a brand major identifier, which must consist of ISO 8859-1 printable characters.
|
|
365
365
|
// Here we check for 8859-1 printable characters (for simplicity, it's a mask which also catches one non-printable character).
|
|
366
366
|
if (
|
|
367
|
-
|
|
368
|
-
(buffer[8] & 0x60) !== 0x00
|
|
367
|
+
checkString('ftyp', {offset: 4}) &&
|
|
368
|
+
(buffer[8] & 0x60) !== 0x00 // Brand major, first character ASCII?
|
|
369
369
|
) {
|
|
370
370
|
// They all can have MIME `video/mp4` except `application/mp4` special-case which is hard to detect.
|
|
371
371
|
// For some cases, we're specific, everything else falls to `video/mp4` with `mp4` extension.
|
|
372
|
-
const brandMajor = uint8ArrayUtf8ByteString(buffer, 8, 12);
|
|
372
|
+
const brandMajor = uint8ArrayUtf8ByteString(buffer, 8, 12).replace('\0', ' ').trim();
|
|
373
373
|
switch (brandMajor) {
|
|
374
374
|
case 'mif1':
|
|
375
375
|
return {ext: 'heic', mime: 'image/heif'};
|
|
@@ -379,23 +379,23 @@ const fileType = input => {
|
|
|
379
379
|
return {ext: 'heic', mime: 'image/heic'};
|
|
380
380
|
case 'hevc': case 'hevx':
|
|
381
381
|
return {ext: 'heic', mime: 'image/heic-sequence'};
|
|
382
|
-
case 'qt
|
|
382
|
+
case 'qt':
|
|
383
383
|
return {ext: 'mov', mime: 'video/quicktime'};
|
|
384
|
-
case 'M4V
|
|
384
|
+
case 'M4V': case 'M4VH': case 'M4VP':
|
|
385
385
|
return {ext: 'm4v', mime: 'video/x-m4v'};
|
|
386
|
-
case 'M4P
|
|
386
|
+
case 'M4P':
|
|
387
387
|
return {ext: 'm4p', mime: 'video/mp4'};
|
|
388
|
-
case 'M4B
|
|
388
|
+
case 'M4B':
|
|
389
389
|
return {ext: 'm4b', mime: 'audio/mp4'};
|
|
390
|
-
case 'M4A
|
|
390
|
+
case 'M4A':
|
|
391
391
|
return {ext: 'm4a', mime: 'audio/x-m4a'};
|
|
392
|
-
case 'F4V
|
|
392
|
+
case 'F4V':
|
|
393
393
|
return {ext: 'f4v', mime: 'video/mp4'};
|
|
394
|
-
case 'F4P
|
|
394
|
+
case 'F4P':
|
|
395
395
|
return {ext: 'f4p', mime: 'video/mp4'};
|
|
396
|
-
case 'F4A
|
|
396
|
+
case 'F4A':
|
|
397
397
|
return {ext: 'f4a', mime: 'audio/mp4'};
|
|
398
|
-
case 'F4B
|
|
398
|
+
case 'F4B':
|
|
399
399
|
return {ext: 'f4b', mime: 'audio/mp4'};
|
|
400
400
|
default:
|
|
401
401
|
if (brandMajor.startsWith('3g')) {
|
|
@@ -1020,6 +1020,20 @@ const fileType = input => {
|
|
|
1020
1020
|
mime: 'application/x-mie'
|
|
1021
1021
|
};
|
|
1022
1022
|
}
|
|
1023
|
+
|
|
1024
|
+
if (check([0x41, 0x52, 0x52, 0x4F, 0x57, 0x31, 0x00, 0x00])) {
|
|
1025
|
+
return {
|
|
1026
|
+
ext: 'arrow',
|
|
1027
|
+
mime: 'application/x-apache-arrow'
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
if (check([0x27, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], {offset: 2})) {
|
|
1032
|
+
return {
|
|
1033
|
+
ext: 'shp',
|
|
1034
|
+
mime: 'application/x-esri-shape'
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1023
1037
|
};
|
|
1024
1038
|
|
|
1025
1039
|
module.exports = fileType;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-type",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.4.2",
|
|
4
4
|
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/file-type",
|
|
@@ -156,7 +156,9 @@
|
|
|
156
156
|
"crx",
|
|
157
157
|
"ktx",
|
|
158
158
|
"dcm",
|
|
159
|
-
"mpc"
|
|
159
|
+
"mpc",
|
|
160
|
+
"arrow",
|
|
161
|
+
"shp"
|
|
160
162
|
],
|
|
161
163
|
"devDependencies": {
|
|
162
164
|
"@types/node": "^12.7.2",
|
package/readme.md
CHANGED
|
@@ -29,18 +29,18 @@ fileType(buffer);
|
|
|
29
29
|
Or from a remote location:
|
|
30
30
|
|
|
31
31
|
```js
|
|
32
|
-
const
|
|
32
|
+
const https = require('https');
|
|
33
33
|
const fileType = require('file-type');
|
|
34
34
|
|
|
35
|
-
const url = 'https://
|
|
35
|
+
const url = 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg';
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
https.get(url, response => {
|
|
38
38
|
response.on('readable', () => {
|
|
39
39
|
const chunk = response.read(fileType.minimumBytes);
|
|
40
40
|
response.destroy();
|
|
41
41
|
|
|
42
42
|
console.log(fileType(chunk));
|
|
43
|
-
//=> {ext: '
|
|
43
|
+
//=> {ext: 'jpg', mime: 'image/jpeg'}
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
46
|
```
|
|
@@ -57,13 +57,13 @@ const fileType = require('file-type');
|
|
|
57
57
|
const read = fs.createReadStream('encrypted.enc');
|
|
58
58
|
const decipher = crypto.createDecipheriv(alg, key, iv);
|
|
59
59
|
|
|
60
|
-
const
|
|
60
|
+
const fileTypeStream = await fileType.stream(stream.pipeline(read, decipher));
|
|
61
61
|
|
|
62
|
-
console.log(
|
|
62
|
+
console.log(fileTypeStream.fileType);
|
|
63
63
|
//=> {ext: 'mov', mime: 'video/quicktime'}
|
|
64
64
|
|
|
65
|
-
const write = fs.createWriteStream(`decrypted.${
|
|
66
|
-
|
|
65
|
+
const write = fs.createWriteStream(`decrypted.${fileTypeStream.fileType.ext}`);
|
|
66
|
+
fileTypeStream.pipe(write);
|
|
67
67
|
})();
|
|
68
68
|
```
|
|
69
69
|
|
|
@@ -245,13 +245,22 @@ Returns a set of supported MIME types.
|
|
|
245
245
|
- [`f4p`](https://en.wikipedia.org/wiki/Flash_Video) - ISO base media file format protected by Adobe Access DRM used by Adobe Flash Player
|
|
246
246
|
- [`f4a`](https://en.wikipedia.org/wiki/Flash_Video) - Audio-only ISO base media file format used by Adobe Flash Player
|
|
247
247
|
- [`f4b`](https://en.wikipedia.org/wiki/Flash_Video) - Audiobook and podcast ISO base media file format used by Adobe Flash Player
|
|
248
|
-
- [`mie`](https://en.wikipedia.org/wiki/Sidecar_file) - Dedicated meta information format which supports storage of binary as well as textual meta information
|
|
248
|
+
- [`mie`](https://en.wikipedia.org/wiki/Sidecar_file) - Dedicated meta information format which supports storage of binary as well as textual meta information
|
|
249
|
+
- [`shp`](https://en.wikipedia.org/wiki/Shapefile) - Geospatial vector data format
|
|
250
|
+
- [`arrow`](https://arrow.apache.org) - Columnar format for tables of data
|
|
249
251
|
|
|
250
252
|
*SVG isn't included as it requires the whole file to be read, but you can get it [here](https://github.com/sindresorhus/is-svg).*
|
|
251
253
|
|
|
252
254
|
*Pull requests are welcome for additional commonly used file types, except for `doc`, `xls`, `ppt`.*
|
|
253
255
|
|
|
254
256
|
|
|
257
|
+
## file-type for enterprise
|
|
258
|
+
|
|
259
|
+
Available as part of the Tidelift Subscription.
|
|
260
|
+
|
|
261
|
+
The maintainers of file-type and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-file-type?utm_source=npm-file-type&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
|
262
|
+
|
|
263
|
+
|
|
255
264
|
## Related
|
|
256
265
|
|
|
257
266
|
- [file-type-cli](https://github.com/sindresorhus/file-type-cli) - CLI for this module
|
|
@@ -262,16 +271,3 @@ Returns a set of supported MIME types.
|
|
|
262
271
|
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
263
272
|
- [Mikael Finstad](https://github.com/mifi)
|
|
264
273
|
- [Ben Brook](https://github.com/bencmbrook)
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
---
|
|
268
|
-
|
|
269
|
-
<div align="center">
|
|
270
|
-
<b>
|
|
271
|
-
<a href="https://tidelift.com/subscription/pkg/npm-file-type?utm_source=npm-file-type&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
|
272
|
-
</b>
|
|
273
|
-
<br>
|
|
274
|
-
<sub>
|
|
275
|
-
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|
276
|
-
</sub>
|
|
277
|
-
</div>
|
package/supported.js
CHANGED
|
@@ -117,7 +117,9 @@ module.exports = {
|
|
|
117
117
|
'asf',
|
|
118
118
|
'ogm',
|
|
119
119
|
'ogx',
|
|
120
|
-
'mpc'
|
|
120
|
+
'mpc',
|
|
121
|
+
'arrow',
|
|
122
|
+
'shp'
|
|
121
123
|
],
|
|
122
124
|
mimeTypes: [
|
|
123
125
|
'image/jpeg',
|
|
@@ -145,6 +147,7 @@ module.exports = {
|
|
|
145
147
|
'application/x-bzip2',
|
|
146
148
|
'application/x-7z-compressed',
|
|
147
149
|
'application/x-apple-diskimage',
|
|
150
|
+
'application/x-apache-arrow',
|
|
148
151
|
'video/mp4',
|
|
149
152
|
'audio/midi',
|
|
150
153
|
'video/x-matroska',
|
|
@@ -228,6 +231,7 @@ module.exports = {
|
|
|
228
231
|
'image/x-panasonic-rw2',
|
|
229
232
|
'image/x-fujifilm-raf',
|
|
230
233
|
'video/x-m4v',
|
|
231
|
-
'video/3gpp2'
|
|
234
|
+
'video/3gpp2',
|
|
235
|
+
'application/x-esri-shape'
|
|
232
236
|
]
|
|
233
237
|
};
|