
Security News
Next.js Patches Critical Middleware Vulnerability (CVE-2025-29927)
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
The is-png npm package is a utility that allows you to check if a given buffer or file is a PNG image. It is useful for validating image formats in various applications.
Check if a buffer is a PNG
This feature allows you to check if a given buffer contains a PNG image. You can read a file into a buffer and then use the isPng function to validate its format.
const isPng = require('is-png');
const fs = require('fs');
const buffer = fs.readFileSync('path/to/image.png');
console.log(isPng(buffer)); // true if the buffer is a PNG, false otherwise
Check if a file is a PNG
This feature allows you to check if a given file is a PNG image by reading the file asynchronously and then using the isPng function to validate its format.
const isPng = require('is-png');
const fs = require('fs');
fs.readFile('path/to/image.png', (err, data) => {
if (err) throw err;
console.log(isPng(data)); // true if the file is a PNG, false otherwise
});
The image-type package detects the file type of a buffer, supporting various image formats including PNG, JPEG, GIF, and more. It provides broader functionality compared to is-png, which is specific to PNG images.
The file-type package is a comprehensive utility for detecting the file type of a buffer or stream. It supports a wide range of file formats, including images, videos, documents, and more. It offers more extensive functionality compared to is-png, which is focused solely on PNG images.
The is-jpg package is similar to is-png but is specific to JPEG images. It allows you to check if a given buffer or file is a JPEG image, providing similar functionality but for a different image format.
Check if a Buffer/Uint8Array is a PNG image
$ npm install is-png
import {readChunk} from 'read-chunk';
import isPng from 'is-png';
const buffer = await readChunk('unicorn.png', {length: 8});
isPng(buffer);
//=> true
import isPng from 'is-png';
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.
FAQs
Check if a Buffer/Uint8Array is a PNG image
The npm package is-png receives a total of 458,684 weekly downloads. As such, is-png popularity was classified as popular.
We found that is-png demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.