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 🙏

© 2024 – Pkg Stats / Ryan Hefner

wasm-brotli

v2.0.2

Published

🗜 WebAssembly compiled Brotli library

Downloads

12,376

Readme

wasm-brotli

WebAssembly compiled Brotli library.

Installation

npm install -S wasm-brotli

The awesome thing about wasm-brotli is that it does not need to compile or download any prebuilt binaries!

Usage

Because WebAssembly is supported on both Node.js and several browsers, wasm-brotli is super easy to use.

Node.js

An example of compressing something and saving it to a file via Node.js.

import { compress } from 'wasm-brotli';
import { writeFile } from 'fs';
import { promisify } from 'util';

const writeFileAsync = promisify(writeFile);

const content = Buffer.from('Hello, world!', 'utf8');

(async () => {
  try {
    const compressedContent = await compress(content);
    await writeFileAsync('./hello_world.txt.br', compressedContent);
  } catch (err) {
    console.error(err);
  }
})();

Browser

An example of compressing something and downloading it from the browser.

import { compress } from 'wasm-brotli';

const content = new TextEncoder('utf-8').encode('Hello, world!');

(async () => {
  try {
    const compressedContent = await compress(content);

    const file = new File([compressedContent], 'hello_world.txt.br', { type: 'application/brotli' });

    const link = document.createElement('a');
    link.setAttribute('href', URL.createObjectURL(file));
    link.setAttribute('download', file.name);
    link.click();
  } catch (err) {
    console.error(err);
  }
})();

Documentation

compress(buffer)

Compress buffer using Brotli compression.

decompress(buffer)

Decompress buffer using Brotli decompression.

Development

To build wasm-brotli you will need to install wasm-pack. After that all that is needed is to do the following:

  1. Install all dependencies.

    npm install
  2. Build the module.

    npm run build
  3. Test the module.

    npm test

Benchmark

  1. Build wasm-brotli if you haven't already done so— see instructions here.

  2. Build and run the benchmark.

    npm run benchmark
  3. Wait a while... The tests might run quite slow.

These results are run on a Dell XPS 13 9360 with an Intel® Core™ i7-7500U CPU @ 2.70GHz × 4 and 16 GB 1866 MHz DDR3 memory, running Ubuntu 19.10:

iltorb (native compress)      1 byte(s)  x 5,159 ops/sec ±9.73% (66 runs sampled)
wasm-brotli (wasm compress)   1 byte(s)  x 49.80 ops/sec ±0.61% (78 runs sampled)
iltorb (native compress)      1024 byte(s)       x 329 ops/sec ±1.63% (81 runs sampled)
wasm-brotli (wasm compress)   1024 byte(s)       x 32.33 ops/sec ±0.77% (76 runs sampled)
iltorb (native compress)      1038336 byte(s)    x 2.23 ops/sec ±1.20% (15 runs sampled)
wasm-brotli (wasm compress)   1038336 byte(s)    x 1.03 ops/sec ±0.93% (10 runs sampled)