
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
Brotli.js is port of the Brotli compression algorithm (as used in the WOFF2 font format) to JavaScript. The decompressor is hand ported, and the compressor is ported with Emscripten. The original C++ source code can be found here.
Install using npm.
npm install brotli
If you want to use brotli in the browser, you should use Browserify to build it.
In node, or in browserify, you can load brotli in the standard way:
var brotli = require('brotli');
You can also require just the decompress function or just the compress function, which is useful for browserify builds.
For example, here's how you'd require just the decompress function.
var decompress = require('brotli/decompress');
Decompresses the given buffer to produce the original input to the compressor.
The outSize parameter is optional, and will be computed by the decompressor
if not provided. Inside a WOFF2 file, this can be computed from the WOFF2 directory.
// decode a buffer where the output size is known
brotli.decompress(compressedData, uncompressedLength);
// decode a buffer where the output size is not known
brotli.decompress(fs.readFileSync('compressed.bin'));
Compresses the given buffer. Pass optional parameters as the second argument.
// encode a buffer of binary data
brotli.compress(fs.readFileSync('myfile.bin'));
// encode some data with options (default options shown)
brotli.compress(fs.readFileSync('myfile.bin'), {
mode: 0, // 0 = generic, 1 = text, 2 = font (WOFF2)
quality: 11, // 0 - 11
lgwin: 22 // window size
});
MIT
zlib is a compression library that offers compression and decompression functionalities similar to brotli but using different algorithms like Deflate and Gzip. It is built into Node.js, making it readily available without additional installation.
snappy is a package that provides bindings to Google's Snappy compression library. It is known for its high-speed compression and decompression, although it typically achieves lower compression ratios compared to Brotli.
lz4 is a package that implements LZ4 compression, which is known for its extremely fast compression and decompression speeds, but like snappy, it may not achieve compression ratios as high as Brotli.
FAQs
A port of the Brotli compression algorithm as used in WOFF2
The npm package brotli receives a total of 5,265,712 weekly downloads. As such, brotli popularity was classified as popular.
We found that brotli demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.