node package manager
Stop writing boring code. Discover, share, and reuse within your team. Create a free org »

is-bmp

is-bmp Build Status

Check if a Buffer/Uint8Array is a BMP image

Used by image-type.

Install

$ npm install --save is-bmp

Usage

Node.js
var readChunk = require('read-chunk'); // npm install read-chunk 
var isBmp = require('is-bmp');
var buffer = readChunk.sync('unicorn.bmp', 0, 2);
 
isBmp(buffer);
//=> true 
Browser
var xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.bmp');
xhr.responseType = 'arraybuffer';
 
xhr.onload = function () {
    isBmp(new Uint8Array(this.response));
    //=> true 
};
 
xhr.send();

API

isBmp(buffer)

Accepts a Buffer (Node.js) or Uint8Array.

It only needs the first 2 bytes.

License

MIT © Sindre Sorhus