file-type 10.10.0 → 10.11.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
@@ -115,7 +115,7 @@ declare namespace fileType {
115
115
 
116
116
  declare const fileType: {
117
117
  /**
118
- Detect the file type of a `Buffer`/`Uint8Array`. The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
118
+ Detect the file type of a `Buffer`/`Uint8Array`/`ArrayBuffer`. The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
119
119
 
120
120
  @param buffer - It only needs the first `.minimumBytes` bytes. The exception is detection of `docx`, `pptx`, and `xlsx` which potentially requires reading the whole file.
121
121
  @returns An object with the detected file type and MIME type or `null` when there was no match.
@@ -147,7 +147,7 @@ declare const fileType: {
147
147
  });
148
148
  ```
149
149
  */
150
- (buffer: Buffer | Uint8Array): fileType.FileTypeResult | null;
150
+ (buffer: Buffer | Uint8Array | ArrayBuffer): fileType.FileTypeResult | null;
151
151
 
152
152
  /**
153
153
  The minimum amount of bytes needed to detect a file type. Currently, it's 4100 bytes, but it can change, so don't hard-code it.
package/index.js CHANGED
@@ -17,8 +17,8 @@ function readUInt64LE(buf, offset = 0) {
17
17
  }
18
18
 
19
19
  const fileType = input => {
20
- if (!(input instanceof Uint8Array || Buffer.isBuffer(input))) {
21
- throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`Buffer\`, got \`${typeof input}\``);
20
+ if (!(input instanceof Uint8Array || input instanceof ArrayBuffer || Buffer.isBuffer(input))) {
21
+ throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`Buffer\` or \`ArrayBuffer\`, got \`${typeof input}\``);
22
22
  }
23
23
 
24
24
  const buf = input instanceof Uint8Array ? input : new Uint8Array(input);
@@ -929,18 +929,23 @@ module.exports.default = fileType;
929
929
 
930
930
  Object.defineProperty(fileType, 'minimumBytes', {value: 4100});
931
931
 
932
- module.exports.stream = readableStream => new Promise(resolve => {
932
+ module.exports.stream = readableStream => new Promise((resolve, reject) => {
933
933
  // Using `eval` to work around issues when bundling with Webpack
934
934
  const stream = eval('require')('stream'); // eslint-disable-line no-eval
935
935
 
936
936
  readableStream.once('readable', () => {
937
937
  const pass = new stream.PassThrough();
938
938
  const chunk = readableStream.read(module.exports.minimumBytes) || readableStream.read();
939
- pass.fileType = fileType(chunk);
939
+ try {
940
+ pass.fileType = fileType(chunk);
941
+ } catch (error) {
942
+ reject(error);
943
+ }
944
+
940
945
  readableStream.unshift(chunk);
941
946
 
942
947
  if (stream.pipeline) {
943
- resolve(stream.pipeline(readableStream, pass));
948
+ resolve(stream.pipeline(readableStream, pass, () => {}));
944
949
  } else {
945
950
  resolve(readableStream.pipe(pass));
946
951
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "file-type",
3
- "version": "10.10.0",
4
- "description": "Detect the file type of a Buffer/Uint8Array",
3
+ "version": "10.11.0",
4
+ "description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/file-type",
7
7
  "author": {
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # file-type [![Build Status](https://travis-ci.org/sindresorhus/file-type.svg?branch=master)](https://travis-ci.org/sindresorhus/file-type)
2
2
 
3
- > Detect the file type of a Buffer/Uint8Array
3
+ > Detect the file type of a Buffer/Uint8Array/ArrayBuffer
4
4
 
5
5
  The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
6
6
 
@@ -99,7 +99,7 @@ Or `null` when there is no match.
99
99
 
100
100
  #### input
101
101
 
102
- Type: `Buffer` `Uint8Array`
102
+ Type: `Buffer | Uint8Array | ArrayBuffer`
103
103
 
104
104
  It only needs the first `.minimumBytes` bytes. The exception is detection of `docx`, `pptx`, and `xlsx` which potentially requires reading the whole file.
105
105