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

is-png

Check if a Buffer/Uint8Array is a PNG image

Install

$ npm install is-png

Usage

Node.js
import {readChunk} from 'read-chunk';
import isPng from 'is-png';

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

isPng(buffer);
//=> true
Browser
import isPng from 'is-png';

const response = await fetch('unicorn.png');
const buffer = await response.arrayBuffer();

isPng(new Uint8Array(buffer));
//=> true

API

isPng(buffer)

Accepts a Buffer (Node.js) or Uint8Array. Returns a boolean of whether buffer is a PNG image.

buffer

The buffer to check. It only needs the first 8 bytes.

Related

  • file-type - Detect the file type of a Buffer/Uint8Array/ArrayBuffer

Current Tags

  • 3.0.1                                ...           latest (3 years ago)

7 Versions

  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           4 years ago
  • 2.0.0                                ...           6 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.0                                ...           10 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (5)

© 2010 - cnpmjs.org x YWFE | Home | YWFE