Formats

Brotli

RFC 7932 read in full. Context modeling and the built-in dictionary of 120 KiB of web words. Read only
IDbrotli05 / 71 container · reads
Format / Prefix codes

Brotli

Context modeling and a built-in dictionary of the web.

Ratio
reads only
Checksum
none
Standard
RFC 7932
Used by
HTTP, WOFF2
group 3 / 7

Containers

brotli
Brotli stream.br · no magic number · no checksum
27 bytes · 1f3200f88dd44e777726aa32…reads back · window 16777200, metaBlocks 1

Access

Importimport { brotli } from "@agntn/compressions/brotli"
CLIcompressions decompress brotli file.br
Tryplayground with the sample above
Kindeflate, zstd

What your browser asked for when it said Accept-Encoding: br. LZ77 with Huffman codes that switch by context, and a built-in dictionary of words that show up on web pages, each one in 121 transformed forms. A distance past the window points into that dictionary instead of into the output.

ts
decompress("brotli", Buffer.from("1f3200f88dd44e777726aa32b40609617b53b358530d6440358300", "hex"));
// { bytes: "hello world! hello world! hello world! hello world!",
//   details: { window: 16777200, metaBlocks: 1 } }

27 bytes from brotli 1.2.0 for 51 bytes of text.

Read only

Same reason as zstd: the writer is a project of its own, and brotli is a package install away. compress("brotli", …) throws and says so.

No magic, no checksum

A brotli stream starts with its window size in a few bits, and that's it. No magic number, no checksum. So identify only counts brotli when it decodes every byte and gives something back, and even then scores it low. Random bytes decode as brotli now and then. A damaged stream can decode into the wrong bytes without an error, because there's nothing to check them against.

The dictionary ships inside the package, deflated and in base64, and gets inflated by this package's own deflate on first use.