A JavaScript port of the Brotli compression algorithm, as used in WOFF2
Перейти к файлу
Devon Govett da44b7ac2a 1.3.1 2016-09-13 20:34:24 -07:00
dec Encode compressed dictionary as base64 - remove brfs dep 2016-09-11 00:23:24 -07:00
enc Update encoder for latest brotli 2016-09-11 00:21:30 -07:00
test Update encoder for latest brotli 2016-09-11 00:21:30 -07:00
vendor Add new submodule 2016-09-10 23:13:31 -07:00
.gitignore Initial hand JS port of the decoder 2015-07-19 16:18:37 -07:00
.gitmodules Add new submodule 2016-09-10 23:13:31 -07:00
.npmignore Add more things to npm ignore 2016-03-27 16:20:37 -07:00
Makefile Update encoder for latest brotli 2016-09-11 00:21:30 -07:00
compress.js Fixed params not being passed in correctly to the encoder 2016-09-13 15:45:57 -07:00
decompress.js Use JS decoder by default 2015-07-20 20:17:03 -07:00
index.js Use JS decoder by default 2015-07-20 20:17:03 -07:00
package.json 1.3.1 2016-09-13 20:34:24 -07:00
readme.md Update readme 2016-09-11 00:28:58 -07:00

readme.md

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

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

License

MIT