Generic byte-level primitives (ByteWriter, ByteReader, CRC-32, deflate/inflate) and PNG/JPEG image encoding/decoding with zero PDF knowledge — the shared utility package for the documents.js family.
Extracted from pdf-codec, where these utilities lived as a directory-isolated subgraph under src/bytes/ + src/image/ with no PDF imports. Both pdf-codec and documents.js consume them from this neutral home rather than one fetching byte utilities from a backend.
Requires Node.js >=20 and pnpm 11.6.0.
pnpm install
pnpm build # tsdown -> dist/ (ESM + CJS + .d.ts)
pnpm test # vitest
pnpm typecheck # tsc --noEmit| Module | Exports |
|---|---|
bytes/writer |
ByteWriter (chunked growable byte-output builder), concatBytes |
bytes/reader |
ByteReader (sequential big/little-endian byte reader), isAsciiWhitespace |
bytes/crc32 |
crc32 (IEEE 802.3 / ZIP / PNG polynomial table-driven CRC-32) |
bytes/flate |
deflate, inflate, inflateTolerant (fflate-backed DEFLATE compression/decompression with a safety cap) |
image/png-encode |
encodePng (raw RGB/RGBA pixels → PNG bytes) |
image/png-decode |
decodePng (PNG bytes → raw pixels), RawImage |
image/png-filter |
filterScanlines, unfilterScanlines (the five PNG scanline filters) |
image/jpeg-info |
readJpegInfo (JPEG header reader: dimensions, components, progressive flag — no sample decoding) |
pnpm add byte-codec
# or
npm install byte-codecMIT