This is a pure esm package contains the zstd n-api addon for node.js & wasm for browsers.
npm install @cloudpss/zstd
import { compress, decompress } from '@cloudpss/zstd';
const compressed = await compress(new TextEncoder().encode('Hello World!'));
const decompressed = await decompress(compressed);
console.log(new TextDecoder().decode(decompressed)); // Hello World!
To explicitly use the wasm or the n-api version, import @cloudpss/zstd/wasm
and @cloudpss/zstd/napi
respectively.
compress(input: BinaryData | Blob, level?: number): Promise<Uint8Array>
compressSync(input: BinaryData, level?: number): Uint8Array
Compresses the input data with the given compression level (default: 4).
decompress(input: BinaryData | Blob): Promise<Uint8Array>
decompressSync(input: BinaryData): Uint8Array
Decompresses the input data.
The type of the current module.
The version of the zstd library.
The maximum size of the input/output buffer.
The default compression level.
Minimum compression level.
Maximum compression level.
MIT