brotli
Compress or decompress data using Brotli
TLDR
Compress a file, creating a compressed version next to the file
Decompress a file, creating an uncompressed version next to the file
Compress a file specifying the output filename
Decompress a Brotli file specifying the output filename
Specify the compression quality (1=fastest (worst), 11=slowest (best))
SYNOPSIS
brotli [OPTION]... [FILE]...
brotli { -d | --decompress } [OPTION]... [FILE]...
brotli { -t | --test } [OPTION]... [FILE]...
PARAMETERS
-d, --decompress
Decompress input files.
-z, --compress
Compress input files (this is the default action).
-f, --force
Overwrite existing output files without prompting.
-k, --keep
Do not delete input files after compression or decompression.
-c, --stdout
Write output to standard output, keep original files.
-o, --output=FILE
Specify the output file name.
-q, --quality=N
Set compression quality (0-11). Higher values mean smaller files but slower compression. Default is 11.
-S, --suffix=SUFFIX
Specify the output filename suffix (default is .br for compression, or no suffix for decompression).
-j, --rm
Remove input files after successful operation (default unless -k is used).
-n, --no-file-information
Do not store or restore the original file name and modification time in the compressed stream header.
-v, --verbose
Enable verbose output, showing progress and detailed information.
-h, --help
Display a help message and exit.
-V, --version
Display version information and exit.
-w, --window=N
Set the LZ77 sliding window size (10-24 bits). Larger window can improve compression but requires more memory. Default is 22 for quality 0-9, and 24 for 10-11.
-D, --dictionary=FILE
Use a custom dictionary for compression. The dictionary file must be in brotli's custom dictionary format.
-t, --test
Test the integrity of compressed files.
DESCRIPTION
brotli is a modern, open-source lossless data compression algorithm developed by Google. It is particularly effective for compressing text-based web content like HTML, CSS, and JavaScript, often achieving better compression ratios than older algorithms like Gzip. While optimized for web assets due to its context-adaptive modeling and a pre-defined static dictionary for common web terms, brotli is a general-purpose compressor. It offers a spectrum of compression quality levels (0-11), allowing users to balance compression speed against file size. Files compressed with brotli typically carry the .br extension. Its fast decompression speed makes it highly suitable for web servers to serve compressed content efficiently.
CAVEATS
While brotli excels at text compression, for highly redundant binary data or very large files, other algorithms like xz or zstd might sometimes offer comparable or better ratios, though often with different speed profiles. Higher compression quality levels (e.g., 10-11) can be significantly slower for compression, making them more suitable for pre-compression of static assets rather than on-the-fly compression.
USAGE WITH PIPES
Like many Unix utilities, brotli can process data from standard input and write to standard output. This makes it highly versatile for use in shell pipelines, for example:
tar cvf - some_dir | brotli -c > archive.tar.br
or
brotli -d -c archive.tar.br | tar xvf -
COMPRESSION QUALITY TRADE-OFFS
The -q (quality) option is vital. A quality of 11 provides maximum compression but is the slowest. For real-time applications or situations where compression speed is critical, lower quality settings (e.g., 4-6) can offer a good balance between compression ratio and speed. Decompression speed is generally fast across all quality levels.
HISTORY
brotli was initially developed by Google in 2013 as a generic compression library. The file format specification and its accompanying command-line tool, brotli, were publicly released in 2015. It quickly gained traction, especially within the web development community, being adopted by major web browsers and servers as a standard for HTTP compression (Content-Encoding: br) due to its superior compression ratios for text-based content compared to gzip.