Wondering what’s next for npm?Check out our public roadmap! »

    is-png
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.0 • Public • Published

    is-png

    Check if a Buffer/Uint8Array is a PNG image

    Install

    $ npm install is-png
    

    Usage

    Node.js
    import readChunk from 'read-chunk'; // npm install read-chunk
    import isPng from 'is-png';
    
    const buffer = readChunk.sync('unicorn.png', 0, 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.

    Related

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

    Install

    npm i is-png

    DownloadsWeekly Downloads

    973,067

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    3.79 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar