is-webp
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');
var isWebp = require('is-webp');
var buffer = readChunk.sync('unicorn.webp', 0, 12);
isWebp(buffer);
Browser
var xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.webp');
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
isWebp(new Uint8Array(this.response));
};
xhr.send();
API
isWebp(buffer)
Accepts a Buffer (Node.js) or Uint8Array.
It only needs the first 12 bytes.
License
MIT © Sindre Sorhus