Skip to content

@hpcc-js/wasm-root


Class: Zstd

Defined in: zstd/src/zstd.ts:27

The Zstandard WASM library, provides a simplified wrapper around the Zstandard c++ library.

See Zstandard for more details.

ts
import { Zstd } from "@hpcc-js/wasm-zstd";

const zstd = await Zstd.load();

//  Generate some "data"
const data = new Uint8Array(Array.from({ length: 100000 }, (_, i) => i % 256));

const compressed_data = zstd.compress(data);
const decompressed_data = zstd.decompress(compressed_data);

Extends

  • WasmLibrary

Methods

load()

static load(): Promise<Zstd>

Defined in: zstd/src/zstd.ts:42

Compiles and instantiates the raw wasm.

INFO

In general WebAssembly compilation is disallowed on the main thread if the buffer size is larger than 4KB, hence forcing load to be asynchronous;

Returns

Promise<Zstd>

A promise to an instance of the Zstd class.


unload()

static unload(): void

Defined in: zstd/src/zstd.ts:54

Unloades the compiled wasm instance.

Returns

void


version()

version(): string

Defined in: zstd/src/zstd.ts:61

Returns

string

The Zstd c++ version


compress()

compress(data, compressionLevel): Uint8Array

Defined in: zstd/src/zstd.ts:74

Parameters

data

Uint8Array

Data to be compressed

compressionLevel

number = ...

Compression v Speed tradeoff, when omitted it will default to zstd.defaultCLevel() which is currently 3.

Returns

Uint8Array

Compressed data.

TIP

A note on compressionLevel: The library supports regular compression levels from 1 up o 22. Levels >= 20, should be used with caution, as they require more memory. The library also offers negative compression levels, which extend the range of speed vs. ratio preferences. The lower the level, the faster the speed (at the cost of compression).


decompress()

decompress(compressedData): Uint8Array

Defined in: zstd/src/zstd.ts:95

Parameters

compressedData

Uint8Array

Data to be compressed

Returns

Uint8Array

Uncompressed data.


defaultCLevel()

defaultCLevel(): number

Defined in: zstd/src/zstd.ts:119

Returns

number

Default compression level (see notes above above).


minCLevel()

minCLevel(): number

Defined in: zstd/src/zstd.ts:123

Returns

number


maxCLevel()

maxCLevel(): number

Defined in: zstd/src/zstd.ts:127

Returns

number

Released under the Apache-2.0 License.