file-type 7.6.0 → 8.1.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.
Files changed (3) hide show
  1. package/index.js +59 -17
  2. package/package.json +2 -2
  3. package/readme.md +4 -0
package/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
- const toBytes = s => Array.from(s).map(c => c.charCodeAt(0));
2
+ const toBytes = s => [...s].map(c => c.charCodeAt(0));
3
3
  const xpiZipFilename = toBytes('META-INF/mozilla.rsa');
4
4
  const oxmlContentTypes = toBytes('[Content_Types].xml');
5
5
  const oxmlRels = toBytes('_rels/.rels');
6
6
 
7
7
  module.exports = input => {
8
- const buf = (input instanceof Uint8Array) ? input : new Uint8Array(input);
8
+ const buf = input instanceof Uint8Array ? input : new Uint8Array(input);
9
9
 
10
10
  if (!(buf && buf.length > 1)) {
11
11
  return null;
@@ -278,7 +278,7 @@ module.exports = input => {
278
278
 
279
279
  if (idPos !== -1) {
280
280
  const docTypePos = idPos + 3;
281
- const findDocType = type => Array.from(type).every((c, i) => sliced[docTypePos + i] === c.charCodeAt(0));
281
+ const findDocType = type => [...type].every((c, i) => sliced[docTypePos + i] === c.charCodeAt(0));
282
282
 
283
283
  if (findDocType('matroska')) {
284
284
  return {
@@ -307,14 +307,27 @@ module.exports = input => {
307
307
  };
308
308
  }
309
309
 
310
- if (
311
- check([0x52, 0x49, 0x46, 0x46]) &&
312
- check([0x41, 0x56, 0x49], {offset: 8})
313
- ) {
314
- return {
315
- ext: 'avi',
316
- mime: 'video/x-msvideo'
317
- };
310
+ // RIFF file format which might be AVI, WAV, QCP, etc
311
+ if (check([0x52, 0x49, 0x46, 0x46])) {
312
+ if (check([0x41, 0x56, 0x49], {offset: 8})) {
313
+ return {
314
+ ext: 'avi',
315
+ mime: 'video/x-msvideo'
316
+ };
317
+ }
318
+ if (check([0x57, 0x41, 0x56, 0x45], {offset: 8})) {
319
+ return {
320
+ ext: 'wav',
321
+ mime: 'audio/x-wav'
322
+ };
323
+ }
324
+ // QLCM, QCP file
325
+ if (check([0x51, 0x4C, 0x43, 0x4D], {offset: 8})) {
326
+ return {
327
+ ext: 'qcp',
328
+ mime: 'audio/qcelp'
329
+ };
330
+ }
318
331
  }
319
332
 
320
333
  if (check([0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9])) {
@@ -361,6 +374,24 @@ module.exports = input => {
361
374
  mime: 'audio/mpeg'
362
375
  };
363
376
  }
377
+
378
+ if (
379
+ check([0xFF, 0xF8], {offset: start, mask: [0xFF, 0xFC]}) // MPEG 2 layer 0 using ADTS
380
+ ) {
381
+ return {
382
+ ext: 'mp2',
383
+ mime: 'audio/mpeg'
384
+ };
385
+ }
386
+
387
+ if (
388
+ check([0xFF, 0xF0], {offset: start, mask: [0xFF, 0xFC]}) // MPEG 4 layer 0 using ADTS
389
+ ) {
390
+ return {
391
+ ext: 'mp4',
392
+ mime: 'audio/mpeg'
393
+ };
394
+ }
364
395
  }
365
396
 
366
397
  if (
@@ -437,13 +468,10 @@ module.exports = input => {
437
468
  };
438
469
  }
439
470
 
440
- if (
441
- check([0x52, 0x49, 0x46, 0x46]) &&
442
- check([0x57, 0x41, 0x56, 0x45], {offset: 8})
443
- ) {
471
+ if (check([0x4D, 0x41, 0x43, 0x20])) {
444
472
  return {
445
- ext: 'wav',
446
- mime: 'audio/x-wav'
473
+ ext: 'ape',
474
+ mime: 'audio/ape'
447
475
  };
448
476
  }
449
477
 
@@ -553,6 +581,13 @@ module.exports = input => {
553
581
  };
554
582
  }
555
583
 
584
+ if (check([0x00, 0x00, 0x02, 0x00])) {
585
+ return {
586
+ ext: 'cur',
587
+ mime: 'image/x-icon'
588
+ };
589
+ }
590
+
556
591
  if (check([0x46, 0x4C, 0x56, 0x01])) {
557
592
  return {
558
593
  ext: 'flv',
@@ -763,5 +798,12 @@ module.exports = input => {
763
798
  }
764
799
  }
765
800
 
801
+ if (check([0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A])) {
802
+ return {
803
+ ext: 'ktx',
804
+ mime: 'image/ktx'
805
+ };
806
+ }
807
+
766
808
  return null;
767
809
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "file-type",
3
- "version": "7.6.0",
3
+ "version": "8.1.0",
4
4
  "description": "Detect the file type of a Buffer/Uint8Array",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/file-type",
@@ -10,7 +10,7 @@
10
10
  "url": "sindresorhus.com"
11
11
  },
12
12
  "engines": {
13
- "node": ">=4"
13
+ "node": ">=6"
14
14
  },
15
15
  "scripts": {
16
16
  "test": "xo && ava"
package/readme.md CHANGED
@@ -114,6 +114,7 @@ It only needs the first 4100 bytes.
114
114
  - [`opus`](https://en.wikipedia.org/wiki/Opus_(audio_format))
115
115
  - [`flac`](https://en.wikipedia.org/wiki/FLAC)
116
116
  - [`wav`](https://en.wikipedia.org/wiki/WAV)
117
+ - [`qcp`](https://en.wikipedia.org/wiki/QCP)
117
118
  - [`amr`](https://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec)
118
119
  - [`pdf`](https://en.wikipedia.org/wiki/Portable_Document_Format)
119
120
  - [`epub`](https://en.wikipedia.org/wiki/EPUB)
@@ -160,6 +161,9 @@ It only needs the first 4100 bytes.
160
161
  - [`odp`](https://en.wikipedia.org/wiki/OpenDocument) - OpenDocument for presentations
161
162
  - [`xml`](https://en.wikipedia.org/wiki/XML)
162
163
  - [`heic`](http://nokiatech.github.io/heif/technical.html)
164
+ - [`cur`](https://en.wikipedia.org/wiki/ICO_(file_format))
165
+ - [`ktx`](https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/)
166
+ - [`ape`](https://en.wikipedia.org/wiki/Monkey%27s_Audio) - Monkey's Audio
163
167
 
164
168
  *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).*
165
169