CLI
Install or run it
npx @agntn/compressions identify mystery.bin
pnpm add -g @agntn/compressions
Give compress, decompress or identify a file. Use - for stdin. list and mcp are the exceptions.
Compress
compressions compress deflate notes.txt --container gzip --level 9 > notes.txt.gz
compressions compress lzma notes.txt --container xz --check sha256 > notes.txt.xz
echo -n "hello world!" | compressions compress bzip2 - --to base64
Raw compressed bytes never go to a terminal. Redirect them, or pass --to base64 or --to hex.
| Flag | Takes |
|---|---|
--container | deflate raw, zlib, gzip. lzma alone, xz. lz4 frame, legacy |
--level | deflate 0 to 9, lzma 0 to 9, bzip2 1 to 9 |
--name, --mtime | deflate with --container gzip: the header fields |
--check | lzma with --container xz: none, crc32, crc64, sha256 |
--checksum | lz4 frame: XXH32 of the content, on by default |
--bits | lzw: the widest code, 10 to 16 |
--from, --to | raw, hex or base64 |
Decompress
compressions decompress deflate notes.txt.gz --container gzip
echo 1f8b08000000000000ffcb48cdc9c95728cf2fca495104006dc2b4030c000000 \
| compressions decompress deflate - --container gzip --from hex
What the stream says about itself goes to stderr, the bytes to stdout:
os: 255
members: 1
hello world!
--limit caps the output, --partial writes what came out before the damage. zstd and brotli decompress here too.
Identify
compressions identify mystery.bin
1 candidate, best first:
1. deflate container gzip, confidence 100: starts with its magic number; checksum matches; decodes to the last byte; decompresses to readable text (os 255, members 1)
12 bytes, text "hello world!"
Each candidate gives format, container, confidence and reasons. Then what the stream said about itself, the size and a preview. The reasons are worth reading. It's the text compressions_identify gives an agent, minus its hint. Pass gzip to decompress --container and you're in.
Nothing fits? One line on stderr, exit code 1. When the bytes start like ZIP, 7-Zip or tar, the line names the archive, which this package doesn't open.
Use --peel to list layers on stderr and send the innermost bytes raw to stdout.
compressions identify nested.bin --peel > inner.txt
3 layers, outermost first:
1. bzip2 container bzip2, confidence 90: starts with its magic number; checksum matches; decodes to the last byte (level 9, blocks 1)
112 bytes, hex fd377a585a000004e6d6b446…
2. lzma container xz, confidence 90: starts with its magic number; checksum matches; decodes to the last byte (check "crc64", blocks 1)
56 bytes, hex 1f8b08000000000000ffcb4d…
3. deflate container gzip, confidence 100: starts with its magic number; checksum matches; decodes to the last byte; decompresses to readable text (os 255, members 1)
42 bytes, text "meet me at the old lighthouse at midnight\n"
Bzip2 around xz around gzip. Somebody really didn't want that note read. The list stays on stderr, so > inner.txt gets only the note.
Data instead of prose
Want data, not prose? identify and list take --json. With identify --peel --json, layers become JSON and data holds the innermost bytes in base64. compress and decompress don't take it. Their stdout is for bytes.
List
compressions list
compressions list deflate
deflate: deflate, RFC 1951. LZ77 with Huffman codes: gzip files, zlib streams, PNG, HTTP and ZIP entries. Compresses and decompresses.
container raw: raw deflate, RFC 1951, no magic number, no checksum
container zlib: zlib, RFC 1950, .zz .zlib, no magic number, checksum Adler-32
container gzip: gzip, RFC 1952, .gz .tgz, magic 1f8b08, checksum CRC-32
option container (raw, zlib, gzip): raw deflate, a zlib stream or a gzip file, default raw, decompress too
option level (0 to 9): 0 stores, 1 is fastest, 9 is smallest, default 6
option name: File name in the gzip header, gzip only
option mtime (0 to 4294967295): Modification time in the gzip header, Unix seconds; 0 leaves it out, default 0, gzip only
That's the same text compressions_info gives an agent. The format comes first, then its containers and options.
Typos and dashes
A dashed word is an option or an error. Mistype --container and the error names it alongside the accepted options:
$ compressions decompress deflate notes.txt.gz --containr gzip
Invalid arguments: unknown option "--containr"; takes --container, --limit, --partial, --from, --to (-o)
Got a file name starting with a dash? Put it after --: compressions decompress deflate --container gzip -- -odd.gz. Numbers get checked before the format runs. A flag owned by another format gets refused by the format itself.
When it fails
Failures print one line on stderr and exit with code 1. A typo doesn't deserve a stack trace. No colors: terminal, pipe, file and transcript read alike.
compressions mcp starts the MCP server. Agents has the rest.