is-webp
Check if a Buffer/Uint8Array is a WebP image
Last updated 5 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install is-webp 
SYNC missed versions from official npm registry.

is-webp

Check if a Buffer/Uint8Array is a WebP image

Install

npm install is-webp

Usage

Node.js
import {readChunk} from 'read-chunk';
import isWebp from 'is-webp';

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

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

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

Related

  • file-type - Detect the file type of a Buffer/Uint8Array
  • is-webp-extended - Extended version of this package which supports checking for animated WebP

Current Tags

  • 2.0.0                                ...           latest (5 years ago)

5 Versions

  • 2.0.0                                ...           5 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           12 years ago
  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (3)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |