Skip to content
Latchkey

bzip2: Compress to .bz2 with -9 in CI

bzip2 compresses each file to .bz2, usually smaller than gzip at the cost of speed, and deletes the original unless you pass -k.

bzip2 trades CPU time for a better ratio than gzip on text-heavy data. In CI it appears as the .bz2 middle ground before xz and zstd took over.

What it does

bzip2 compresses a single file with the Burrows-Wheeler transform, appends .bz2, and removes the source unless -k is given. bunzip2 or bzip2 -d reverses it. Like gzip, it is single-file; pair it with tar for directories.

Common usage

Terminal
bzip2 -9 dump.sql               # best ratio, replaces dump.sql
bzip2 -k build.tar             # keep build.tar
tar cf - src/ | bzip2 -9 > src.tar.bz2
bzip2 -d logs.bz2              # decompress

Options

FlagWhat it does
-9Largest block size, best compression (default)
-1Smallest block size, fastest
-k / --keepKeep the input file
-c / --stdoutWrite to stdout
-d / --decompressDecompress (like bunzip2)
-t / --testTest integrity without writing output

In CI

bzip2 is single-threaded and slow at -9; on multi-core runners pbzip2 produces compatible .bz2 files in a fraction of the time. For new pipelines, zstd usually beats bzip2 on both speed and ratio.

Common errors in CI

"bzip2: Compressed file ends unexpectedly" means a truncated download or a partially written artifact; re-fetch it. "bzip2: (stdin) is not a bzip2 file" means the input is not .bz2. "bzip2: Output file <name> already exists" needs -f to overwrite.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →