---
title: "CLI"
description: "compress and decompress and identify and list from the terminal. Files or stdin in raw bytes or hex or base64"
canonical_url: "https://compressions.agntn.dev/guide/cli"
---
# CLI

> compress and decompress and identify and list from the terminal. Files or stdin in raw bytes or hex or base64

## Install or run it

```bash
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

```bash
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`.

<table>
<thead>
  <tr>
    <th>
      Flag
    </th>
    
    <th>
      Takes
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --container
      </code>
    </td>
    
    <td>
      deflate <code>
        raw
      </code>
      
      , <code>
        zlib
      </code>
      
      , <code>
        gzip
      </code>
      
      . lzma <code>
        alone
      </code>
      
      , <code>
        xz
      </code>
      
      . lz4 <code>
        frame
      </code>
      
      , <code>
        legacy
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --level
      </code>
    </td>
    
    <td>
      deflate 0 to 9, lzma 0 to 9, bzip2 1 to 9
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --name
      </code>
      
      , <code>
        --mtime
      </code>
    </td>
    
    <td>
      deflate with <code>
        --container gzip
      </code>
      
      : the header fields
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --check
      </code>
    </td>
    
    <td>
      lzma with <code>
        --container xz
      </code>
      
      : <code>
        none
      </code>
      
      , <code>
        crc32
      </code>
      
      , <code>
        crc64
      </code>
      
      , <code>
        sha256
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --checksum
      </code>
    </td>
    
    <td>
      lz4 frame: XXH32 of the content, on by default
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --bits
      </code>
    </td>
    
    <td>
      lzw: the widest code, 10 to 16
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --from
      </code>
      
      , <code>
        --to
      </code>
    </td>
    
    <td>
      <code>
        raw
      </code>
      
      , <code>
        hex
      </code>
      
       or <code>
        base64
      </code>
    </td>
  </tr>
</tbody>
</table>

## Decompress

```bash
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:

```text
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

```bash
compressions identify mystery.bin
```

```text
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.

```bash
compressions identify nested.bin --peel > inner.txt
```

```text
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

```bash
compressions list
compressions list deflate
```

```text
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:

```text
$ 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](https://compressions.agntn.dev/guide/agents) has the rest.


## Sitemap

See the full [sitemap](https://compressions.agntn.dev/sitemap.md) for all pages.
