JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 710926
  • Score
    100M100P100Q176593F
  • License MIT

Check if a Buffer/Uint8Array is a PNG image

Package Exports

  • is-png

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (is-png) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

is-png Build Status

Check if a Buffer/Uint8Array is a PNG image

Used by image-type.

Install

$ npm install --save is-png
$ bower install --save is-png
$ component install sindresorhus/is-png

Usage

Node.js
var readChunk = require('read-chunk'); // npm install read-chunk
var isPng = require('is-png');
var buffer = readChunk('unicorn.png', 0, 4);

isPng(buffer);
//=> true
Browser
var xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.png');
xhr.responseType = 'arraybuffer';

xhr.onload = function () {
    isPng(new Uint8Array(this.response));
    //=> true
};

xhr.send();

API

isPng(buffer)

Accepts a Buffer (Node.js) or Uint8Array.

It only needs the first 4 bytes.

License

MIT © Sindre Sorhus