Socket
Socket
Sign inDemoInstall

is-png

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    is-png

Check if a Buffer/Uint8Array is a PNG image


Version published
Maintainers
1
Install size
4.80 kB
Created

Readme

Source

is-png Build Status

Check if a Buffer/Uint8Array is a PNG image

Install

$ npm install is-png

Usage

Node.js
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
Browser
(async () => {
	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.

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

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 20 Apr 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc