From brotli-wasm
brotli-wasm compiles the Rust brotli crates to WebAssembly. comprs uses libbrotli, the C library that browsers and node:zlib use, in a WebAssembly build that loads itself when it is imported, and the native addon in Node.js, Deno and Bun.
import brotliPromise from 'brotli-wasm';const brotli = await brotliPromise;const compressed = brotli.compress(data, { quality: 11 });const restored = brotli.decompress(compressed);import { compressSync, decompressSync } from '@derodero24/comprs/next';const compressed = compressSync(data, { format: 'brotli', level: 11 });const restored = decompressSync(compressed, { format: 'brotli' });- Loading. There is no promise to await: the entry module instantiates the WebAssembly module with top-level
awaitwhen it is imported. See Browsers for the bundler setup. - Streams. Replace brotli-wasm’s
CompressStreamandDecompressStreamwithnew CompressionStream('brotli')andnew DecompressionStream('brotli')of the unified API, which work withpipeThrough(). - Quality. comprs compresses at quality 6 by default. Pass
levelfor another quality, from 0 to 11. - Size. comprs’s full WebAssembly module holds zstd, gzip and LZ4 as well: 568 KB with gzip. If brotli is all you need, import
@derodero24/comprs/next/brotli, which loads a module with brotli alone: 337 KB with gzip (see Browsers). - Dictionaries. comprs takes a custom brotli dictionary (see Dictionaries).