@@ -45,25 +45,25 @@ yarn add snappy
4545
4646### Targets
4747
48- | Rust triple | Platform | CI |
49- | ------------------------------- | -------------------- | ------------------------------- |
50- | ` x86_64-pc-windows-msvc ` | Windows x64 | tested — node 22, 24 |
51- | ` aarch64-pc-windows-msvc ` | Windows arm64 | tested — node 22, 24 |
52- | ` i686-pc-windows-msvc ` | Windows x32 | built, not tested |
53- | ` x86_64-apple-darwin ` | macOS x64 | tested — node 22, 24 |
54- | ` aarch64-apple-darwin ` | macOS arm64 | tested — node 22, 24 |
55- | ` x86_64-unknown-linux-gnu ` | Linux x64 gnu | tested — node 22, 24 |
56- | ` x86_64-unknown-linux-musl ` | Linux x64 musl | tested — node 22, 24 |
57- | ` aarch64-unknown-linux-gnu ` | Linux arm64 gnu | tested — node 22, 24 |
58- | ` aarch64-unknown-linux-musl ` | Linux arm64 musl | tested — node 22, 24 |
59- | ` armv7-unknown-linux-gnueabihf ` | Linux armv7 gnu | tested — node 22 only |
60- | ` s390x-unknown-linux-gnu ` | Linux s390x | tested — node 22, 24 |
61- | ` x86_64-unknown-freebsd ` | FreeBSD x64 | built, not tested |
62- | ` powerpc64le-unknown-linux-gnu ` | Linux ppc64le | built, not tested |
63- | ` riscv64gc-unknown-linux-gnu ` | Linux riscv64 | built, not tested |
64- | ` aarch64-linux-android ` | Android arm64 | built, not tested |
65- | ` arm-linux-androideabi ` | Android armv7 | built, not tested |
66- | ` aarch64-unknown-linux-ohos ` | OpenHarmony arm64 | built, not tested |
48+ | Rust triple | Platform | CI |
49+ | ------------------------------- | -------------------- | --------------------------------------- |
50+ | ` x86_64-pc-windows-msvc ` | Windows x64 | tested — node 22, 24 |
51+ | ` aarch64-pc-windows-msvc ` | Windows arm64 | tested — node 22, 24 |
52+ | ` i686-pc-windows-msvc ` | Windows x32 | built, not tested |
53+ | ` x86_64-apple-darwin ` | macOS x64 | tested — node 22, 24 |
54+ | ` aarch64-apple-darwin ` | macOS arm64 | tested — node 22, 24 |
55+ | ` x86_64-unknown-linux-gnu ` | Linux x64 gnu | tested — node 22, 24 |
56+ | ` x86_64-unknown-linux-musl ` | Linux x64 musl | tested — node 22, 24 |
57+ | ` aarch64-unknown-linux-gnu ` | Linux arm64 gnu | tested — node 22, 24 |
58+ | ` aarch64-unknown-linux-musl ` | Linux arm64 musl | tested — node 22, 24 |
59+ | ` armv7-unknown-linux-gnueabihf ` | Linux armv7 gnu | tested — node 22 only |
60+ | ` s390x-unknown-linux-gnu ` | Linux s390x | tested — node 22, 24 |
61+ | ` x86_64-unknown-freebsd ` | FreeBSD x64 | built, not tested |
62+ | ` powerpc64le-unknown-linux-gnu ` | Linux ppc64le | built, not tested |
63+ | ` riscv64gc-unknown-linux-gnu ` | Linux riscv64 | built, not tested |
64+ | ` aarch64-linux-android ` | Android arm64 | built, not tested |
65+ | ` arm-linux-androideabi ` | Android armv7 | built, not tested |
66+ | ` aarch64-unknown-linux-ohos ` | OpenHarmony arm64 | built, not tested |
6767| ` wasm32-wasip1-threads ` | wasm32-wasi, browser | tested — node 24 (` NAPI_RS_FORCE_WASI ` ) |
6868
6969Eighteen targets: eleven CI-tested, seven built but not exercised.
@@ -81,13 +81,62 @@ served with `Cross-Origin-Opener-Policy: same-origin` and
8181
8282## API
8383
84+ ### One-shot (raw Snappy block format)
85+
8486``` ts
8587export function compressSync(input : Buffer | string | ArrayBuffer | Uint8Array ): Buffer
8688export function compress(input : Buffer | string | ArrayBuffer | Uint8Array ): Promise <Buffer >
8789export function uncompressSync(compressed : Buffer ): Buffer
8890export function uncompress(compressed : Buffer ): Promise <Buffer >
8991```
9092
93+ ### Streaming (framed Snappy format )
94+
95+ Streaming uses the [Snappy frame format ](https :// github.com/google/snappy/blob/master/framing_format.txt)
96+ (file extension ` .sz ` ). This is ** not ** the same wire format as the one - shot APIs
97+ above — framed output cannot be passed to ` uncompress() ` , and raw blocks cannot
98+ be passed to the stream decompressors .
99+
100+ #### Incremental classes
101+
102+ ` ` ` js
103+ import { Compressor, Decompressor } from 'snappy'
104+
105+ const compressor = new Compressor()
106+ const parts = [compressor.update('Hello '), compressor.update('snappy 🚀'), await compressor.finish()]
107+ const compressed = Buffer.concat(parts)
108+
109+ const decompressor = new Decompressor()
110+ const restored = Buffer.concat([decompressor.update(compressed), await decompressor.finish()])
111+ console.log(restored.toString('utf8')) // Hello snappy 🚀
112+ ` ` `
113+
114+ The valid stream is the concatenation of every ` update() ` output plus the ` finish() ` tail .
115+
116+ #### Web Streams
117+
118+ ` ` ` js
119+ import { compressStream, uncompressStream } from 'snappy'
120+
121+ const restored = uncompressStream(compressStream(source)) // ReadableStream<Uint8Array>
122+ ` ` `
123+
124+ ` input ` must be a WHATWG ` ReadableStream ` ; wrap a Node ` Readable ` with ` Readable.toWeb() ` .
125+
126+ On wasm / browser builds the native transforms are unavailable ; a buffered class - API
127+ polyfill is used automatically .
128+
129+ #### Node Duplex factories
130+
131+ ` ` ` js
132+ import { createReadStream, createWriteStream } from 'node:fs'
133+ import { createCompressStream, createUncompressStream } from 'snappy'
134+
135+ createReadStream('input.txt').pipe(createCompressStream()).pipe(createWriteStream('input.txt.sz'))
136+ ` ` `
137+
138+ Requires a modern Node .js with Web Streams and ` Duplex.fromWeb ` (effectively Node 18 + ).
139+
91140## Performance
92141
93142### Hardware
0 commit comments