1. is-png
Check if a Buffer/Uint8Array is a PNG image
is-png
Package: is-png
Created by: sindresorhus
Last modified: Sun, 19 Jun 2022 02:48:12 GMT
Version: 3.0.1
License: MIT
Downloads: 2,806,567
Repository: https://github.com/sindresorhus/is-png

Install

npm install is-png
yarn add is-png

is-png

Check if a Buffer/Uint8Array is a PNG image

Install

$ npm install is-png

Usage

Node.js
 import {readChunk} from 'read-chunk';
import isPng from 'is-png';

const buffer = await readChunk('unicorn.png', {length: 8});

isPng(buffer);
//=> true
Browser
 import isPng from 'is-png';

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

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin