Guide

Getting Started

Install the package and open your first gzip file. Every format answers the same two calls
The API and the tool list can still move. Pin exact versions if you build on it now.This code has never had a security audit. Do not use it in production, with real funds or with sensitive data, and don't point it at untrusted bytes at scale. It is meant for agents, puzzles, CTFs and local experiments. It comes as is, without warranty of any kind, and the authors are not liable for any loss, as the MIT license states. Anything that matters wants an audited library.

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

shell
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

ts
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