is-webp

Check if a Buffer/Uint8Array is a WebP image

Usage no npm install needed!

<script type="module">
  import isWebp from 'https://cdn.skypack.dev/is-webp';
</script>

README

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