Skip to content

A JavaScript port of the Brotli compression algorithm, as used in WOFF2

Notifications You must be signed in to change notification settings

foliojs/brotli.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
Aug 27, 2018
Feb 28, 2024
Feb 28, 2024
Jul 19, 2015
Sep 11, 2016
Mar 27, 2016
Feb 28, 2024
Feb 28, 2024
Feb 28, 2024
Jul 21, 2015
Jul 21, 2015
Jun 8, 2022
Jun 8, 2022
Feb 28, 2024

Repository files navigation

Brotli.js

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.

Installation and usage

Install using npm.

npm install brotli

If you want to use brotli in the browser, you should use a bundler to build it.

In node, or in bundlers, 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 browser builds. For example, here's how you'd require just the decompress function.

var decompress = require('brotli/decompress');

API

brotli.decompress(buffer, [outSize])

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'));

brotli.compress(buffer, isText = false)

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
  dictionary: ''
});

License

MIT

About

A JavaScript port of the Brotli compression algorithm, as used in WOFF2

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages