#brotli #web-worker #brotli-decompressor #rust

brotli-dec-wasm

Brotli decompressor for browsers and web workers with WASM, which still has a small size (about 300KB)

1 stable release

2.0.1 Jul 13, 2023

#743 in WebAssembly

MIT/Apache

16KB
204 lines

brotli-dec-wasm

npm

Brotli decompressor for browsers and web workers with WASM, which still has a small size (about 300KB)

If you are looking for a compressor, see Alternatives

Features

Usage

Starting from v2.0.0, this package becomes an exact drop-in replacement of brotli-wasm. You can simply replace import brotli from 'brotli-wasm' with import brotli from 'brotli-dec-wasm' to switch from or to this package.

More detailed usage can be found in brotli-wasm Usage section.

Notice that brotli-wasm is going to release a new version for the new stream pattern, which is also used by this package, and has not update the README yet. If you are urgent, you can refer to the unit tests in brotli-wasm:test/brotli.spec.ts to see how to use by examples.

Problems

Broken in webpack 5

BREAKING CHANGE: Since webpack 5 WebAssembly is not enabled by default and flagged as experimental feature. You need to enable one of the WebAssembly experiments via 'experiments.asyncWebAssembly: true' (based on async modules) or 'experiments.syncWebAssembly: true' (like webpack 4, deprecated).

Set experiments.syncWebAssembly: true for old code, experiments.asyncWebAssembly: true for new code.

Implementation

The code is quite simple, which is just a wrapper of the crate brotli-decompressor (other than crate brotli, though brotli depends on brotli-decompressor)

Build configuration such as opt-level = "s", are fine-tuned with manual tests, to make the bundle as small as possible

Maintenance

The package is at least used by myself in my blog mylmoe, which provides a page to (de)compress Brotli online

Alternatives

  • brotli-wasm: A reliable compressor and decompressor for Brotli, supporting node & browsers via wasm. If you need a compressor, use it. Actively maintained by an organization.

More alternatives are available in brotli-wasm Alternatives section

One surprising thing is, in js folder of the offical google/brotli repository, there is a pure JavaScript decompressor implementation, which is even a little smaller than this package in size. However, it is not published on NPM. I can not imagine the reason and since that, I do not suggest you to use it.

Security

At least >= v1.3.3

  • < v1.3.3: Rust dependency wee_alloc is unmaintained and has open serious issues. Use version >= 1.3.3 to replace it with the default Rust allocator on wasm32 targets.

License

Copyright (C) myl7

SPDX-License-Identifier: MIT OR Apache-2.0

At your option. Unless otherwise explicitly stated.

Dependencies

~4MB
~60K SLoC