1. is-webp
Check if a Buffer/Uint8Array is a WebP image
is-webp
Package: is-webp
Created by: sindresorhus
Last modified: Sun, 19 Jun 2022 02:53:36 GMT
Version: 2.0.0
License: MIT
Downloads: 2,230
Repository: https://github.com/sindresorhus/is-webp

Install

npm install is-webp
yarn add is-webp

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.

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code