Skip to content

Class: Zstd

zstd.Zstd

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);

Hierarchy

Methods

load

load(): Promise<Zstd>

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.

Defined in

zstd.ts:42


unload

unload(): void

Unloades the compiled wasm instance.

Returns

void

Defined in

zstd.ts:54


version

version(): string

Returns

string

The Zstd c++ version

Defined in

zstd.ts:61


compress

compress(data, compressionLevel?): Uint8Array

Parameters

NameTypeDescription
dataUint8ArrayData to be compressed
compressionLevelnumberCompression 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).

Defined in

zstd.ts:74


decompress

decompress(compressedData): Uint8Array

Parameters

NameTypeDescription
compressedDataUint8ArrayData to be compressed

Returns

Uint8Array

Uncompressed data.

Defined in

zstd.ts:95


defaultCLevel

defaultCLevel(): number

Returns

number

Default compression level (see notes above above).

Defined in

zstd.ts:119


minCLevel

minCLevel(): number

Returns

number

Defined in

zstd.ts:123


maxCLevel

maxCLevel(): number

Returns

number

Defined in

zstd.ts:127

Released under the Apache-2.0 License.