file-type 11.0.0 → 11.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.
package/index.d.ts CHANGED
@@ -9,6 +9,10 @@ declare namespace fileType {
9
9
  | 'webp'
10
10
  | 'flif'
11
11
  | 'cr2'
12
+ | 'orf'
13
+ | 'arw'
14
+ | 'dng'
15
+ | 'nef'
12
16
  | 'tif'
13
17
  | 'bmp'
14
18
  | 'jxr'
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const {stringToBytes, readUInt64LE, tarHeaderChecksumMatches} = require('./util');
2
+ const {stringToBytes, readUInt64LE, tarHeaderChecksumMatches, uint8ArrayUtf8ByteString} = require('./util');
3
3
 
4
4
  const xpiZipFilename = stringToBytes('META-INF/mozilla.rsa');
5
5
  const oxmlContentTypes = stringToBytes('[Content_Types].xml');
@@ -73,7 +73,7 @@ const fileType = input => {
73
73
  };
74
74
  }
75
75
 
76
- // Needs to be before `tif` check
76
+ // `cr2`, `orf`, and `arw` need to be before `tif` check
77
77
  if (
78
78
  (check([0x49, 0x49, 0x2A, 0x0]) || check([0x4D, 0x4D, 0x0, 0x2A])) &&
79
79
  check([0x43, 0x52], {offset: 8})
@@ -84,6 +84,34 @@ const fileType = input => {
84
84
  };
85
85
  }
86
86
 
87
+ if (check([0x49, 0x49, 0x52, 0x4F, 0x08, 0x00, 0x00, 0x00, 0x18])) {
88
+ return {
89
+ ext: 'orf',
90
+ mime: 'image/x-olympus-orf'
91
+ };
92
+ }
93
+
94
+ if (check([0x49, 0x49, 0x2A, 0x00, 0x10, 0xFB, 0x86, 0x01])) {
95
+ return {
96
+ ext: 'arw',
97
+ mime: 'image/x-sony-arw'
98
+ };
99
+ }
100
+
101
+ if (check([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2D])) {
102
+ return {
103
+ ext: 'dng',
104
+ mime: 'image/x-adobe-dng'
105
+ };
106
+ }
107
+
108
+ if (check([0x49, 0x49, 0x2A, 0x00, 0x30, 0x3D, 0x72, 0x01, 0x1C])) {
109
+ return {
110
+ ext: 'nef',
111
+ mime: 'image/x-nikon-nef'
112
+ };
113
+ }
114
+
87
115
  if (
88
116
  check([0x49, 0x49, 0x2A, 0x0]) ||
89
117
  check([0x4D, 0x4D, 0x0, 0x2A])
@@ -289,7 +317,7 @@ const fileType = input => {
289
317
  ) {
290
318
  // They all can have MIME `video/mp4` except `application/mp4` special-case which is hard to detect.
291
319
  // For some cases, we're specific, everything else falls to `video/mp4` with `mp4` extension.
292
- const brandMajor = buffer.toString('utf8', 8, 12);
320
+ const brandMajor = uint8ArrayUtf8ByteString(buffer, 8, 12);
293
321
  switch (brandMajor) {
294
322
  case 'mif1':
295
323
  return {ext: 'heic', mime: 'image/heif'};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "file-type",
3
- "version": "11.0.0",
3
+ "version": "11.1.0",
4
4
  "description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/file-type",
@@ -46,6 +46,10 @@
46
46
  "webp",
47
47
  "flif",
48
48
  "cr2",
49
+ "orf",
50
+ "arw",
51
+ "dng",
52
+ "nef",
49
53
  "tif",
50
54
  "bmp",
51
55
  "jxr",
package/readme.md CHANGED
@@ -129,7 +129,11 @@ Type: [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream
129
129
  - [`gif`](https://en.wikipedia.org/wiki/GIF)
130
130
  - [`webp`](https://en.wikipedia.org/wiki/WebP)
131
131
  - [`flif`](https://en.wikipedia.org/wiki/Free_Lossless_Image_Format)
132
- - [`cr2`](https://fileinfo.com/extension/cr2)
132
+ - [`cr2`](https://fileinfo.com/extension/cr2) - Canon Raw image file (v2)
133
+ - [`orf`](https://en.wikipedia.org/wiki/ORF_format) - Olympus Raw image file
134
+ - [`arw`](https://en.wikipedia.org/wiki/Raw_image_format#ARW) - Sony Alpha Raw image file
135
+ - [`dng`](https://en.wikipedia.org/wiki/Digital_Negative) - Adobe Digital Negative image file
136
+ - [`nef`](https://www.nikonusa.com/en/learn-and-explore/a/products-and-innovation/nikon-electronic-format-nef.html) - Nikon Electronic Format image file
133
137
  - [`tif`](https://en.wikipedia.org/wiki/Tagged_Image_File_Format)
134
138
  - [`bmp`](https://en.wikipedia.org/wiki/BMP_file_format)
135
139
  - [`jxr`](https://en.wikipedia.org/wiki/JPEG_XR)
@@ -232,7 +236,7 @@ Type: [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream
232
236
 
233
237
  *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).*
234
238
 
235
- *Pull request welcome for additional commonly used file types.*
239
+ *Pull requests are welcome for additional commonly used file types.*
236
240
 
237
241
 
238
242
  ## Related
package/util.js CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  exports.stringToBytes = string => [...string].map(character => character.charCodeAt(0));
4
4
 
5
+ const uint8ArrayUtf8ByteString = (array, start, end) => {
6
+ return String.fromCharCode(...array.slice(start, end));
7
+ };
8
+
5
9
  exports.readUInt64LE = (buffer, offset = 0) => {
6
10
  let n = buffer[offset];
7
11
  let mul = 1;
@@ -39,7 +43,7 @@ exports.tarHeaderChecksumMatches = buffer => { // Does not check if checksum fie
39
43
  signedBitSum += byte & MASK_8TH_BIT; // Add signed bit to signed bit sum
40
44
  }
41
45
 
42
- const readSum = parseInt(buffer.toString('utf8', 148, 154), 8); // Read sum in header
46
+ const readSum = parseInt(uint8ArrayUtf8ByteString(buffer, 148, 154), 8); // Read sum in header
43
47
 
44
48
  // Some implementations compute checksum incorrectly using signed bytes
45
49
  return (
@@ -50,3 +54,5 @@ exports.tarHeaderChecksumMatches = buffer => { // Does not check if checksum fie
50
54
  readSum === (sum - (signedBitSum << 1))
51
55
  );
52
56
  };
57
+
58
+ exports.uint8ArrayUtf8ByteString = uint8ArrayUtf8ByteString;