Skip to content
/ zstd Public

Zstd n-api addon for node.js & wasm for browsers.

License

Notifications You must be signed in to change notification settings

CloudPSS/zstd

Repository files navigation

@cloudpss/zstd

check Codacy coverage Codacy Badge npm version

This is a pure esm package contains the zstd n-api addon for node.js & wasm for browsers.

Installation

npm install @cloudpss/zstd

Usage

Basic

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.

API

Module @cloudpss/zstd / @cloudpss/zstd/wasm / @cloudpss/zstd/napi

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.

TYPE: 'napi' | 'wasm'

The type of the current module.

ZSTD_VERSION(): string

The version of the zstd library.

Module @cloudpss/zstd/config

MAX_SIZE: number

The maximum size of the input/output buffer.

DEFAULT_LEVEL: number

The default compression level.

MIN_LEVEL: number

Minimum compression level.

MAX_LEVEL: number

Maximum compression level.

License

MIT