Package Exports
- file-type
- file-type/index
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (file-type) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
file-type 
Detect the file type of a Buffer/Uint8Array
Install
$ npm install --save file-type
$ bower install --save file-type
$ component install sindresorhus/file-type
Usage
Node.js
var readChunk = require('read-chunk'); // npm install read-chunk
var fileType = require('file-type');
var buffer = readChunk('unicorn.png', 0, 12);
fileType(buffer);
//=> png
Browser
var xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.png');
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
fileType(new Uint8Array(this.response));
//=> png
};
xhr.send();
API
fileType(buffer)
Returns one of the supported file types or false
.
buffer
Type: buffer
(Node.js), uint8array
It only needs the first 12 bytes.
CLI
$ npm install --global file-type
$ file-type --help
Usage
$ cat <filename> | file-type
$ file-type <filename>
Example
$ cat unicorn.png | file-type
png
Supported file types
PR welcome for additional file types
License
MIT © Sindre Sorhus