snappy
August 12, 2026 ยท View on GitHub
!!! For snappy@6.x and below, please go to node-snappy.
More background about the 6-7 changes, please read this, Thanks @kesla .
๐ Help me to become a full-time open-source developer by sponsoring me on Github
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 | Linux x64 gnu | tested โ node 22, 24 |
x86_64-unknown-linux-musl | Linux x64 musl | tested โ node 22, 24 |
aarch64-unknown-linux-gnu | Linux arm64 gnu | tested โ node 22, 24 |
aarch64-unknown-linux-musl | Linux arm64 musl | tested โ node 22, 24 |
armv7-unknown-linux-gnueabihf | Linux armv7 gnu | tested โ node 22 only |
s390x-unknown-linux-gnu | Linux s390x | tested โ node 22, 24 |
x86_64-unknown-freebsd | FreeBSD x64 | built, not tested |
powerpc64le-unknown-linux-gnu | Linux ppc64le | built, not tested |
riscv64gc-unknown-linux-gnu | Linux riscv64 | built, not tested |
aarch64-linux-android | Android arm64 | built, not tested |
arm-linux-androideabi | Android armv7 | built, not tested |
aarch64-unknown-linux-ohos | OpenHarmony arm64 | built, not tested |
wasm32-wasip1-threads | wasm32-wasi, browser | tested โ node 24 (NAPI_RS_FORCE_WASI) |
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.
API
One-shot (raw Snappy block format)
export function compressSync(input: Buffer | string | ArrayBuffer | Uint8Array): Buffer
export function compress(input: Buffer | string | ArrayBuffer | Uint8Array): Promise<Buffer>
export function uncompressSync(compressed: Buffer): Buffer
export 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.
Web Streams
import { compressStream, uncompressStream } from 'snappy'
const restored = uncompressStream(compressStream(source)) // ReadableStream<Uint8Array>
input must be a WHATWG ReadableStream; wrap a Node Readable with Readable.toWeb().
On wasm / browser builds the native transforms are unavailable; a buffered class-API polyfill is used automatically.
Node Duplex factories
import { createReadStream, createWriteStream } from 'node:fs'
import { createCompressStream, createUncompressStream } from 'snappy'
createReadStream('input.txt').pipe(createCompressStream()).pipe(createWriteStream('input.txt.sz'))
Requires a modern Node.js with Web Streams and Duplex.fromWeb (effectively Node 18+).
Performance
Hardware
OS: Windows 11 x86_64
Host: Micro-Star International Co., Ltd. MS-7C35
Kernel: 10.0.22000
Terminal: Windows Terminal
CPU: AMD Ryzen 9 5950X (32) @ 3.400GHz
Memory: 32688MiB
Result
Running "Compress" suite...
Progress: 100%
snappy:
4 220 ops/s, ยฑ0.66% | fastest
snappy-v6:
2 018 ops/s, ยฑ0.84% | 52.18% slower
gzip:
233 ops/s, ยฑ0.52% | slowest, 94.48% slower
deflate:
235 ops/s, ยฑ0.45% | 94.43% slower
brotli:
7 ops/s, ยฑ0.51% | slowest, 99.85% slower
Finished 4 cases!
Fastest: snappy
Slowest: brotli
Running "Decompress" suite...
Progress: 100%
snappy:
8 528 ops/s, ยฑ1.03% | fastest
snappy-v6:
6 357 ops/s, ยฑ1.76% | 25.46% slower
gzip:
1 406 ops/s, ยฑ1.80% | slowest, 83.51% slower
deflate:
1 435 ops/s, ยฑ1.88% | 83.17% slower
brotli:
1 208 ops/s, ยฑ1.50% | slowest, 86.99% slower
Finished 4 cases!
Fastest: snappy
Slowest: brotli