Formats

bzip2

Burrows-Wheeler transform then move-to-front then Huffman. Slow and small on text with a CRC on every block
IDbzip202 / 71 container · reads and writes
Format / Block sorting

bzip2

Sorts every rotation of a block first, then codes what lines up.

Ratio
9% of the input, on text
Checksum
CRC-32/BZIP2
Standard
bzip2 1.0.8 (Julian Seward)
Used by
source tarballs, Wikipedia dumps
group 1 / 7

Containers

bzip2
bzip2.bz2 .tbz2 · magic 425a68 · CRC-32/BZIP2
54 bytes · 425a68393141592653592e79…reads back · level 9, blocks 1

Options

level1 to 9
default 9 · compress
Block size in hundreds of kilobytes, 1 to 9

Access

Importimport { bzip2 } from "@agntn/compressions/bzip2"
CLIcompressions compress bzip2 notes.txt > file.bz2
Tryplayground with the sample above

bzip2 doesn't look for repeats the way the LZ77 family does. It sorts. Every rotation of a block gets sorted, and the last column of that sort puts similar contexts next to each other. Then move-to-front turns those runs into small numbers, and Huffman codes eat the small numbers. On text it's a beautiful trick. On short input it's mostly overhead:

ts
compress("bzip2", "hello world!").length;  // 49 bytes, for 12

Levels

level is the block size, from 100 kB at 1 to 900 kB at 9, the default. Bigger blocks sort more context together and compress better, and the reader needs more memory. Below the block size the level changes nothing but the h1…h9 in the header, which comes back as details.level.

Checksums

Every block carries the CRC-32/BZIP2 of its output, the MSB-first one, and the stream ends with a CRC combined from all of them. Both get checked. Streams written one after another, the way pbzip2 writes them, decompress into one output, and details.streams counts them when there's more than one.

Randomized blocks, which bzip2 stopped writing before 0.9.5, are an UnsupportedError. Nobody has made one in this century.