node package manager
Loosely couple your services. Use Orgs to version and reuse your code. Create a free org »

is-webp

is-webp Build Status

Check if a Buffer/Uint8Array is a WebP image

Used by image-type.

Install

$ npm install --save is-webp

Usage

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

API

isWebp(buffer)

Accepts a Buffer (Node.js) or Uint8Array.

It only needs the first 12 bytes.

License

MIT © Sindre Sorhus