Kevin 29b9a0c50c clean && clean html base | 4 years ago | |
---|---|---|
.. | ||
index.d.ts | 4 years ago | |
index.js | 4 years ago | |
license | 4 years ago | |
package.json | 4 years ago | |
readme.md | 4 years ago |
Check if a Buffer/Uint8Array is a PNG image
$ npm install is-png
const readChunk = require('read-chunk'); // npm install read-chunk
const isPng = require('is-png');
const buffer = readChunk.sync('unicorn.png', 0, 8);
isPng(buffer);
//=> true
(async () => {
const response = await fetch('unicorn.png');
const buffer = await response.arrayBuffer();
isPng(new Uint8Array(buffer));
//=> true
})();
Accepts a Buffer (Node.js) or Uint8Array. Returns a boolean
of whether buffer
is a PNG image.
The buffer to check. It only needs the first 8 bytes.
MIT © Sindre Sorhus