npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

brotli-lib

v0.0.7

Published

TypeScript Brotli encoder and decoder

Readme

brotli-lib

npm version

TypeScript Brotli encoder and decoder

Install

npm install brotli-lib

Usage

import { brotliDecode } from 'brotli-lib/decode'

const decompressed = brotliDecode(compressed)
import { brotliEncode } from 'brotli-lib/encode'

const compressed = brotliEncode(data, { quality: 11 })
import { brotliEncode, brotliDecode } from 'brotli-lib'

API

Decode

function brotliDecode(
  data: Uint8Array,
  options?: { maxOutputSize?: number; customDictionary?: Uint8Array }
): Uint8Array

function brotliDecodedSize(data: Uint8Array): number  // -1 if multi-metablock

Encode

function brotliEncode(
  data: Uint8Array,
  options?: {
    quality?: number   // 0-11, default 11
    lgwin?: number     // window bits 10-24, default 22
    mode?: EncoderMode // GENERIC, TEXT, or FONT
  }
): Uint8Array

class BrotliEncoder {
  constructor(options?: BrotliEncodeOptions)
  update(chunk: Uint8Array): void
  finish(): Uint8Array
}

FONT mode uses distance coding parameters optimized for transformed font data. It doesn't improve compression on raw TTF/OTF files - the gains come from WOFF2's font-specific transforms (glyf, loca, hmtx) applied before brotli compression

Performance

Decode

| | brotli-lib | brotli.js | Google decode.ts | |--|------------|-----------|---------------| | Speed (vs Google) | 1.2x | 0.5-0.6x | 1x | | Custom dictionary | yes | no | yes | | Compressed static dict | yes | yes | no |

Decode times (Apple M2 Max, Node 22):

| File | brotli-lib | brotli.js | Google decode.ts | |------|------------|-----------|---------------| | enc-ttf (305 KB) | 2.3 ms | 4.4 ms | 2.9 ms | | enc-otf (253 KB) | 2.2 ms | 4.3 ms | 2.8 ms | | enc-var-ttf (788 KB) | 5.8 ms | 11.6 ms | 7.0 ms | | noto-tc (7 MB) | 47 ms | 90 ms | 57 ms |

2x faster than brotli.js, ~20% faster than Google's JS decoder

Encode

Encoder vs Node.js native zlib.brotliCompressSync (quality 11):

| Input | brotli-lib | node:zlib | vs native | |-------|-----------|-----------|-----------| | 13 B | 0.001 ms | 0.16 ms | 160x faster | | 4.5 KB | 0.27 ms | 0.33 ms | 1.2x faster | | 45 KB | 3.0 ms | 1.4 ms | 2x slower |

Much faster for tiny inputs (no native binding overhead), faster for medium, ~2x slower for large

Run npm run bench to reproduce

Subpath exports

| Import | Export size (gzip) | |--------|--------------------| | brotli-lib/encode | 25 KB | | brotli-lib/decode | 66 KB | | brotli-lib | 90 KB |

The 122 KB static dictionary is compressed to 52 KB and bootstrapped at runtime (à la Devon Govett's brotli.js).

License

MIT

Derived from Google's brotli (MIT)

Maintained by @jpt