Skip to content

Repository files navigation

byte-codec

GitHub npm Release CI

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.

byte-codec has no internal dependencies in the documents.js family — its only external dependency is fflate for raw DEFLATE/zlib compression. Both pdf-codec and documents.js depend on it:

graph TD
    bytecodec("byte-codec")
    pdfcodec("pdf-codec")
    documents("documents.js")

    bytecodec --> pdfcodec
    bytecodec --> documents

    click bytecodec "https://github.com/ExaDev/byte-codec" "byte-codec"
    click pdfcodec "https://github.com/ExaDev/pdf-codec" "pdf-codec"
    click documents "https://github.com/ExaDev/documents.js" "documents.js"

    style bytecodec fill:#f9a825,stroke:#333,stroke-width:3px
Loading

Getting started

Requires Node.js >=20 and pnpm 11.6.0.

pnpm install
pnpm build          # tsdown -> dist/ (ESM + CJS + .d.ts)
pnpm typecheck      # tsc -p tsconfig.json && tsc -p tsconfig.node.json (dual tsconfig)
pnpm lint           # eslint . --fix --cache --max-warnings 0
pnpm test           # vitest run
pnpm test:watch     # vitest
pnpm test:workers   # vitest run --config vitest.workers.config.ts

What it provides

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)

Install

pnpm add byte-codec
# or
npm install byte-codec

npm aliases

This package also publishes under the following alternate npm name — the identical build, same version, republished by CI alongside the primary byte-codec package:

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages