png-chunks-extract

Extract raw chunk data from a PNG file for parsing metadata or building custom PNG tooling.

Library
npm
v1.0.0
35stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
22/100Needs Attention
Development Activity0
Maintenance0
Community16
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
54/100Fair
Architecture50
Code Quality55
Innovation40
Learning Curve70

png-chunks-extract is a tiny, focused JavaScript utility that splits a PNG file’s binary buffer into its constituent chunks — IHDR, IDAT, tEXt, IEND, and any others — validating the PNG signature and each chunk’s CRC along the way. It works on both Node.js Buffers and Uint8Arrays, making it usable in server-side scripts and in the browser alike. Rather than trying to be a full PNG decoder, it exposes just the chunk-splitting primitive, leaving decompression and pixel decoding to other tools, which makes it a natural building block for metadata readers, steganography tools, or custom PNG encoders/decoders.

What You Get

  • A single extract(data) function that accepts a Buffer or Uint8Array and returns an array of { name, data } chunk objects
  • PNG signature validation with descriptive errors for corrupted or non-PNG input
  • Per-chunk CRC-32 verification using the crc-32 dependency to detect corrupted files
  • Works identically in Node.js and browser environments since it only depends on typed arrays
  • Zero-configuration API with no classes or setup — just call the function and iterate the result

Common Use Cases

  • Reading PNG metadata chunks (tEXt, iTXt, zTXt) embedded by other tools
  • Building a custom PNG parser or re-encoder on top of the extracted chunk list
  • Implementing steganography tools that hide or extract data in PNG ancillary chunks
  • Validating that a PNG file is well-formed before further processing in a pipeline

Under The Hood

Architecture - The library exposes one function, extractChunks, which walks the byte buffer sequentially: it checks the 8-byte PNG signature, then loops reading a 4-byte big-endian length, a 4-byte chunk name, the chunk payload, and a trailing 4-byte CRC, pushing { name, data } objects into an array until it hits the IEND marker or runs out of bytes. There is no internal state beyond a shared scratch Uint8Array/Int32Array/Uint32Array pair used to reinterpret bytes as integers without allocating per chunk. Tech Stack - Plain JavaScript (CommonJS, module.exports) with a single runtime dependency, crc-32, used to verify each chunk’s checksum; devDependencies are tape and tap-spec for testing. No build step or TypeScript. Code Quality - The file is short and readable with inline comments explaining each byte-offset decision; test.js exercises extraction against a bundled test.png fixture using tape assertions, but there is no coverage for malformed-input edge cases beyond the explicit signature/CRC error throws already in the code. API Design - The API is a single default export function taking one argument and returning one array, with no configuration options, making it trivial to learn and drop into a larger PNG-handling pipeline, though the lack of streaming support means the whole file must be in memory.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search