Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-png

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-png - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

index.d.ts

23

index.js
'use strict';
module.exports = function (buf) {
if (!buf || buf.length < 8) {
module.exports = buffer => {
if (!buffer || buffer.length < 8) {
return false;
}
return buf[0] === 137 &&
buf[1] === 80 &&
buf[2] === 78 &&
buf[3] === 71 &&
buf[4] === 13 &&
buf[5] === 10 &&
buf[6] === 26 &&
buf[7] === 10;
return (
buffer[0] === 0x89 &&
buffer[1] === 0x50 &&
buffer[2] === 0x4E &&
buffer[3] === 0x47 &&
buffer[4] === 0x0D &&
buffer[5] === 0x0A &&
buffer[6] === 0x1A &&
buffer[7] === 0x0A
);
};
{
"name": "is-png",
"version": "1.1.0",
"description": "Check if a Buffer/Uint8Array is a PNG image",
"license": "MIT",
"repository": "sindresorhus/is-png",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
},
"files": [
"index.js"
],
"keywords": [
"png",
"portable",
"network",
"graphics",
"image",
"img",
"pic",
"picture",
"photo",
"type",
"detect",
"check",
"is",
"exif",
"binary",
"buffer",
"uint8array"
],
"devDependencies": {
"mocha": "*",
"read-chunk": "^1.0.0"
}
"name": "is-png",
"version": "2.0.0",
"description": "Check if a Buffer/Uint8Array is a PNG image",
"license": "MIT",
"repository": "sindresorhus/is-png",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"png",
"portable",
"network",
"graphics",
"image",
"picture",
"photo",
"type",
"detect",
"check",
"is",
"exif",
"binary",
"buffer",
"uint8array"
],
"devDependencies": {
"@types/node": "^11.13.5",
"ava": "^1.4.1",
"read-chunk": "^3.2.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
# is-png [![Build Status](https://travis-ci.org/sindresorhus/is-png.svg?branch=master)](https://travis-ci.org/sindresorhus/is-png)
> Check if a Buffer/Uint8Array is a [PNG](http://en.wikipedia.org/wiki/Portable_Network_Graphics) image
> Check if a Buffer/Uint8Array is a [PNG](https://en.wikipedia.org/wiki/Portable_Network_Graphics) image
Used by [image-type](https://github.com/sindresorhus/image-type).
## Install
```sh
$ npm install --save is-png
```
$ npm install is-png
```

@@ -20,5 +18,5 @@

```js
var readChunk = require('read-chunk'); // npm install read-chunk
var isPng = require('is-png');
var buffer = readChunk.sync('unicorn.png', 0, 8);
const readChunk = require('read-chunk'); // npm install read-chunk
const isPng = require('is-png');
const buffer = readChunk.sync('unicorn.png', 0, 8);

@@ -32,12 +30,9 @@ isPng(buffer);

```js
var xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.png');
xhr.responseType = 'arraybuffer';
(async () => {
const response = await fetch('unicorn.png');
const buffer = await response.arrayBuffer();
xhr.onload = function () {
isPng(new Uint8Array(this.response));
isPng(new Uint8Array(buffer));
//=> true
};
xhr.send();
})();
```

@@ -50,9 +45,16 @@

Accepts a Buffer (Node.js) or Uint8Array.
Accepts a Buffer (Node.js) or Uint8Array. Returns a `boolean` of whether `buffer` is a PNG image.
It only needs the first 8 bytes.
#### buffer
The buffer to check. It only needs the first 8 bytes.
## Related
- [file-type](https://github.com/sindresorhus/file-type) - Detect the file type of a Buffer/Uint8Array/ArrayBuffer
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc