Fastest Snappy compression library in Node.js, powered by napi-rs and rust-snappy.
For small size data, snappyjs is faster, and it support browser. But it doesn't have async API, which is important for Node.js program.
Install this package
yarn add snappy
Support matrix
Full matrix as text
Node.js
engines.node is >= 10. CI tests Node 22 and Node 24.
Targets
Rust triple
Platform
CI
x86_64-pc-windows-msvc
Windows x64
tested — node 22, 24
aarch64-pc-windows-msvc
Windows arm64
tested — node 22, 24
i686-pc-windows-msvc
Windows x32
built, not tested
x86_64-apple-darwin
macOS x64
tested — node 22, 24
aarch64-apple-darwin
macOS arm64
tested — node 22, 24
x86_64-unknown-linux-gnu
API
One-shot (raw Snappy block format)
export function compressSync(input: Buffer | string | ArrayBuffer | Uint8Array): Bufferexport function compress(input: Buffer | string | ArrayBuffer | Uint8Array): Promise<Buffer>export function uncompressSync(compressed: Buffer): Bufferexport function uncompress(compressed: Buffer): Promise<Buffer>
Streaming (framed Snappy format)
Streaming uses the Snappy frame format
(file extension .sz). This is not the same wire format as the one-shot APIs
above — framed output cannot be passed to uncompress(), and raw blocks cannot
be passed to the stream decompressors.
Incremental classes
import { Compressor, Decompressor } from 'snappy'const compressor = new Compressor()const parts = [compressor.update('Hello '), compressor.update('snappy 🚀'), await compressor.finish()]const compressed = Buffer.concat(parts)const decompressor = new Decompressor()const restored = Buffer.concat([decompressor.update(compressed), await decompressor.finish()])console.log(restored.toString('utf8')) // Hello snappy 🚀
The valid stream is the concatenation of every update() output plus the finish() tail.
Eighteen targets: eleven CI-tested, seven built but not exercised.
Browser
Bundlers resolve the wasm package through the browser export condition. The wasm
build allocates shared memory and spawns worker threads, so SharedArrayBuffer must be
available — the page has to be
cross-origin isolated,
served with Cross-Origin-Opener-Policy: same-origin and
Cross-Origin-Embedder-Policy: require-corp.