Appearance
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
↳
Zstd
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
unload
▸ unload(): void
Unloades the compiled wasm instance.
Returns
void
Defined in
version
▸ version(): string
Returns
string
The Zstd c++ version
Defined in
compress
▸ compress(data
, compressionLevel?
): Uint8Array
Parameters
Name | Type | Description |
---|---|---|
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).
Defined in
decompress
▸ decompress(compressedData
): Uint8Array
Parameters
Name | Type | Description |
---|---|---|
compressedData | Uint8Array | Data to be compressed |
Returns
Uint8Array
Uncompressed data.
Defined in
defaultCLevel
▸ defaultCLevel(): number
Returns
number
Default compression level (see notes above above).
Defined in
minCLevel
▸ minCLevel(): number
Returns
number
Defined in
maxCLevel
▸ maxCLevel(): number
Returns
number