Getting Started
Why this exists
Hand a model a blob that starts with 1f 8b and ask what's inside. It knows that's gzip. It will even describe gzip to you, beautifully. What it can't do is run Huffman decoding in its head, so it guesses the contents. Confidently.
So the model should call something that actually decompresses. @agntn/compressions is that something. Same thing in your TypeScript, your terminal and your agent.
Every format here is written from its spec. RFC 1950, 1951 and 1952 for zlib, deflate and gzip. RFC 8878 for zstd, RFC 7932 for brotli. The xz file format, the LZMA spec, the LZ4 frame format, bzip2 and Unix compress after their reference code. No zlib binding, no liblzma, no WASM. The checksums come from @agntn/hashes, base64 and hex for the tools from @agntn/encodings.
Install
pnpm add @agntn/compressions
Node.js 26 or newer. The library itself touches nothing from node:*, which is why this site runs it in your browser.
First calls
import { compress, decompress, identify } from "@agntn/compressions";
const gz = compress("deflate", "hello world!", { container: "gzip" });
// Uint8Array(32), starting 1f 8b 08
new TextDecoder().decode(decompress("deflate", gz, { container: "gzip" }).bytes);
// "hello world!"
identify(compress("lzma", "hello world!", { container: "xz" }))[0];
// { format: "lzma", container: "xz", confidence: 100, confirmed: true, … }
compress takes a string, read as UTF-8, or a Uint8Array, and gives bytes back. decompress gives bytes back plus details for whatever the stream carried: a gzip file name, the check xz used, how many bytes followed the stream. Don't know the format? identify tries every container whose start fits and shows its reasoning.
gzip isn't a format of its own here, it's deflate in a gzip container. Same for zlib and raw deflate, and xz and .lzma are both LZMA. Containers explains why that's one option instead of five names.
Pick your door
- Compressing and decompressing for the two calls, the format objects and the subpaths.
- Containers for gzip, zlib, xz and the lz4 frames, and what each one wraps.
- Checksums for CRC-32, Adler-32, CRC-64, XXH32 and XXH64, and what happens when one doesn't match.
- Identify and peel for the mystery blob somebody just sent you.
- Limits and partial reads for bombs, truncated downloads and broken streams.
- CLI and Agents for the terminal and for MCP, Pi, OMP and the AI SDK.
- Every format for the whole registry, sortable.