brotli-wasm is a JavaScript/TypeScript library providing Brotli compression and decompression capabilities across both Node.js (v18 and above) and browser environments, powered by WebAssembly. It wraps the well-regarded Rust Brotli crate (currently v5 as of `brotli-wasm` v3.x), compiling it to WASM for broad compatibility. The current stable version is 3.0.1, with major version updates occurring when significant breaking changes are introduced, such as API overhauls or minimum engine version bumps. A key differentiator is its consistent, battle-tested API that abstracts away the complexities of WASM loading and environment-specific implementations, allowing developers to use a single codebase for compression needs in diverse JavaScript runtimes. It offers both a simple `compress`/`decompress` API for buffers and advanced `CompressStream`/`DecompressStream` classes for streaming data, making it suitable for various use cases from file processing to network communication. It explicitly states no runtime dependencies.
npm install brotli-wasmVerified import paths — ran on the pinned version, not inferred.
Demonstrates asynchronous loading and basic Brotli compression/decompression in a browser-compatible environment using `TextEncoder` and `TextDecoder`.
Upgrade your Node.js environment to v18.0.0 or higher.
Thoroughly test existing Brotli compressed data and new compression results after upgrading to v3.0.0 to ensure compatibility and expected behavior.
Refactor code using `CompressStream` and `DecompressStream` to retrieve output data and status from the result object returned by `compress()`/`decompress()` methods, rather than querying stream state directly.
Always use `await brotliPromise` or `await import('brotli-wasm').then(m => m.default)` to ensure the WebAssembly module is loaded and initialized before attempting to use its functions.Ensure the default export is awaited: `const brotli = await brotliPromise;` or `const brotli = await import('brotli-wasm').then(m => m.default);`In browser environments, use `TextEncoder` and `TextDecoder` for converting strings to/from `Uint8Array`, or include a `Buffer` polyfill like `browserify-zlib` if `Buffer` is strictly required.
Use ES Module `import brotliPromise from 'brotli-wasm';` and ensure your bundler (Webpack, Vite, Rollup) or Node.js environment is configured to handle ES Modules and WebAssembly correctly.
No dependency data recorded yet.