Browse by type
WebAssembly compiled Brotli library.
npm install -S wasm-brotli
The awesome thing about
wasm-brotliis that it does not need to compile or download any prebuilt binaries!
Because WebAssembly is supported on both Node.js and several browsers,
wasm-brotli is super easy to use.
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);
}
})();
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);
}
})();
buffer <Uint8Array>Compress buffer using Brotli compression.
buffer <Uint8Array>Decompress buffer using Brotli decompression.
method <BROTLI_COMPRESS> | <BROTLI_DECOMPRESS>buffer <Uint8Array>The function that compress and decompress wrap. Pass any of the constants
below and a buffer to compress or decompress.
Constant, reference, for compressing a buffer with brotli.
Constant, reference, for decompressing a buffer with brotli.
Want to see how fast this is? Go to the benchmark directory to see results, instructions on running your own benchmark, and more.
To build wasm-brotli you will need to install Docker, and
pull rustlang/rust:nightly. After that all that is needed is
to do the following:
npm install
npm run build
npm test
$ claude mcp add wasm-brotli \
-- python -m otcore.mcp_server <graph>