Skip to content

sindresorhus/is-bmp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

04ccd3f · Sep 2, 2021

History

14 Commits
Sep 2, 2021
Mar 22, 2018
Sep 2, 2021
Mar 22, 2018
Mar 22, 2018
Apr 21, 2014
Apr 21, 2014
Sep 2, 2021
Sep 2, 2021
Sep 2, 2021
Sep 2, 2021
Sep 2, 2021

Repository files navigation

is-bmp

Check if a Buffer/Uint8Array is a BMP image

Install

$ npm install is-bmp

Usage

Node.js
import {readChunk} from 'read-chunk';
import isBmp from 'is-bmp';

const buffer = await readChunk('unicorn.bmp', {length: 2});

isBmp(buffer);
//=> true
Browser
const xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.bmp');
xhr.responseType = 'arraybuffer';

xhr.onload = () => {
	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.

Related

  • file-type - Detect the file type of a Buffer/Uint8Array