Zstd API Reference
This document provides a concise API reference for the Zstd class and the related ZstdModule interface, which provide compression and decompression functionality using the Zstandard (zstd) algorithm, with support for both Node.js and React Native environments.
Class: Zstd
Provides static methods for compressing and decompressing binary data using zstd compression, automatically selecting an appropriate implementation based on the runtime environment.
compress
public static compress(data: Uint8Array): Uint8Array
Compresses input data using Zstandard compression.
-
data(required, Uint8Array): The raw input data to compress.
-
A
Uint8Arraycontaining the compressed data.
-
Throws an error if no compatible zstd module is available in the environment.
-
Internally selects either the native Node.js
zstd-napimodule or the React Nativereact-native-zstdmodule. -
For React Native, performs necessary data conversions to align the APIs.
decompress
public static decompress(data: Uint8Array): Uint8Array
Decompresses input data previously compressed with Zstandard.
-
data(required, Uint8Array): The compressed input data to decompress.
-
A
Uint8Arraycontaining the decompressed original data.
-
Throws an error if no compatible zstd module is available in the environment.
-
Uses the first available zstd module in the environment as with
compress. -
Handles required data conversions for React Native implementations.
Internal Functions (not part of public API)
getAvailableZstdModule
function getAvailableZstdModule(): ZstdModule
Determines and returns a compatible Zstandard compression module available in the current runtime.
-
A
ZstdModuleinstance capable of compressing and decompressing data.
-
Throws an error if neither the Node.js
zstd-napipackage nor the React Nativereact-native-zstdpackage is found, with instructions for installation.
-
Tries Node.js native binding
zstd-napifirst. -
If unavailable, tries React Native binding
react-native-zstd, adapting API usage with data conversion.