Skip to content

Commit

Permalink
Update docs and types with ArrayBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Apr 10, 2019
1 parent 4a4b530 commit ae0eb33
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ declare namespace fileType {

declare const fileType: {
/**
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.
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.
@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.
@returns An object with the detected file type and MIME type or `null` when there was no match.
Expand Down Expand Up @@ -147,7 +147,7 @@ declare const fileType: {
});
```
*/
(buffer: Buffer | Uint8Array): fileType.FileTypeResult | null;
(buffer: Buffer | Uint8Array | ArrayBuffer): fileType.FileTypeResult | null;

/**
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.
Expand Down
1 change: 1 addition & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as fs from 'fs';

expectType<FileTypeResult | null>(fileType(new Buffer([0xff, 0xd8, 0xff])));
expectType<FileTypeResult | null>(fileType(new Uint8Array([0xff, 0xd8, 0xff])));
expectType<FileTypeResult | null>(fileType(new ArrayBuffer([0xff, 0xd8, 0xff])));

const result = fileType(new Buffer([0xff, 0xd8, 0xff]));
if (result != null) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "file-type",
"version": "10.10.0",
"description": "Detect the file type of a Buffer/Uint8Array",
"description": "Detect the file type of a Buffer/Uint8Array/ArrayBuffer",
"license": "MIT",
"repository": "sindresorhus/file-type",
"author": {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# file-type [![Build Status](https://travis-ci.org/sindresorhus/file-type.svg?branch=master)](https://travis-ci.org/sindresorhus/file-type)

> Detect the file type of a Buffer/Uint8Array
> 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.

Expand Down Expand Up @@ -99,7 +99,7 @@ Or `null` when there is no match.

#### input

Type: `Buffer` `Uint8Array`
Type: `Buffer` `Uint8Array` `ArrayBuffer`

It only needs the first `.minimumBytes` bytes. The exception is detection of `docx`, `pptx`, and `xlsx` which potentially requires reading the whole file.

Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,8 @@ test('validate the input argument type', t => {
t.notThrows(() => {
fileType(new Uint8Array());
});

t.notThrows(() => {
fileType(new ArrayBuffer());
});
});

0 comments on commit ae0eb33

Please sign in to comment.