# brotli

> A port of the Brotli compression algorithm as used in WOFF2

Latest version **1.3.3** (published 2022-06-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install brotli
pnpm add brotli
yarn add brotli
bun add brotli
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.3 |
| Published | 2022-06-08 |
| First published | 2014-09-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/brotli) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 538 |
| Author | Devon Govett |
| Maintainers | devongovett |
| Keywords | compress, decompress, encode, decode |

## Links

- npm: https://www.npmjs.com/package/brotli
- Repository: https://github.com/devongovett/brotli.js
- Issues: https://github.com/devongovett/brotli.js/issues
- npm.io page: https://npm.io/package/brotli

## Dependencies (1)

- [base64-js](https://npm.io/package/base64-js.md) ^1.1.2

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.3.3 (latest) — 2022-06-08
- 1.3.2 — 2017-05-02
- 1.3.1 — 2016-09-14
- 1.3.0 — 2016-09-11
- 1.2.0 — 2016-03-27
- 1.1.0 — 2015-04-02
- 1.0.2 — 2015-02-07
- 1.0.1 — 2015-02-03
- 1.0.0 — 2014-09-29

## README

# Brotli.js

Brotli.js is port of the [Brotli](http://tools.ietf.org/html/draft-alakuijala-brotli-01) compression algorithm (as used in the [WOFF2](http://www.w3.org/TR/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](http://github.com/google/brotli).

## Installation and usage

Install using npm.

    npm install brotli

If you want to use brotli in the browser, you should use [Browserify](http://browserify.org/) to build it.

In node, or in browserify, you can load brotli in the standard way:

```javascript
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.

```javascript
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.

```javascript
// 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.

```javascript
// 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

---
_Source: https://npm.io/package/brotli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
