png-chunks-extract
Extract raw chunk data from a PNG file for parsing metadata or building custom PNG tooling.
Repository Health
Technical Analysis
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-32dependency 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.
Used by 4 apps in this directory
Element Web
Team Chat · Collaboration
A polished, self-hostable Matrix client for secure, decentralized messaging and collaboration that puts your organization in full control of its data.
Huly Platform
Project Management · Team Chat · Collaboration
Open-source all-in-one workspace that replaces Linear, Jira, Slack, and Notion for product and engineering teams.
Outline
Knowledge Management · Collaboration
A fast, real-time collaborative knowledge base for growing teams built on React, Node.js, and ProseMirror.
SillyTavern
AI Assistants
The power-user LLM frontend that unifies dozens of AI backends with a rich scripting engine, immersive Visual Novel mode, and a thriving extension ecosystem.