Check if a Buffer/Uint8Array is a BMP image
$ npm install is-bmp
const readChunk = require('read-chunk');
const isBmp = require('is-bmp');
const buffer = readChunk.sync('unicorn.bmp', 0, 2);
isBmp(buffer);
//=> true
const xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.bmp');
xhr.responseType = 'arraybuffer';
xhr.onload = () => {
isBmp(new Uint8Array(this.response));
//=> true
};
xhr.send();
Accepts a Buffer (Node.js) or Uint8Array.
It only needs the first 2 bytes.
- file-type - Detect the file type of a Buffer/Uint8Array
MIT © Sindre Sorhus