### Install zstddec Source: https://github.com/donmccurdy/zstddec-wasm/blob/main/README.md Install the zstddec package using npm. ```shell npm install --save zstddec ``` -------------------------------- ### Install Dependencies and Build Project Source: https://github.com/donmccurdy/zstddec-wasm/blob/main/README.md Install project dependencies using yarn and build the project. ```shell yarn install yarn build ``` -------------------------------- ### ZSTDDecoder Initialization and Decoding Source: https://github.com/donmccurdy/zstddec-wasm/blob/main/README.md This snippet shows how to initialize the ZSTDDecoder and use it to decompress data. It requires the compressed data and optionally the uncompressed size. ```APIDOC ## ZSTDDecoder API ### Description Provides methods to initialize and use a WebAssembly-based Zstandard decoder. ### Initialization ```javascript import { ZSTDDecoder } from 'zstddec'; const decoder = new ZSTDDecoder(); await decoder.init(); ``` ### Decoding ```javascript // Assuming 'compressedArray' is your compressed data (e.g., Uint8Array) // and 'uncompressedSize' is the expected size of the decompressed data (optional but recommended) const decompressedArray = decoder.decode( compressedArray, uncompressedSize ); ``` ### Limitations - The `decode()` method may fail if `uncompressedSize` is not provided. This is a known issue potentially related to WASM bindings. ``` -------------------------------- ### Initialize and Decode with ZSTDDecoder Source: https://github.com/donmccurdy/zstddec-wasm/blob/main/README.md Initialize the ZSTDDecoder and decode a compressed array. Ensure uncompressedSize is provided to avoid potential errors. ```javascript import { ZSTDDecoder } from 'zstddec'; const decoder = new ZSTDDecoder(); await decoder.init(); const decompressedArray = decoder.decode( compressedArray, uncompressedSize ); ``` -------------------------------- ### Build zstd Source: https://github.com/donmccurdy/zstddec-wasm/blob/main/README.md Build the zstd library from source. ```shell # build zstd make cd build/single_file_libs ./create_single_file_decoder.sh ``` -------------------------------- ### Run Tests Source: https://github.com/donmccurdy/zstddec-wasm/blob/main/README.md Execute project tests using yarn. ```shell yarn test ``` -------------------------------- ### Compile zstddec.wasm Source: https://github.com/donmccurdy/zstddec-wasm/blob/main/README.md Compile the zstddeclib.c file into a WebAssembly module for decoding. ```shell # build wasm emcc zstddeclib.c -s EXPORTED_FUNCTIONS="['_ZSTD_decompress', '_ZSTD_findDecompressedSize', '_ZSTD_isError', '_malloc', '_free']" -Wl,--no-entry -s WASM=1 -Oz -g0 -flto -s ALLOW_MEMORY_GROWTH=1 -s FILESYSTEM=0 -s STANDALONE_WASM=1 -DNDEBUG=1 -s PURE_WASI=0 -o zstddec.wasm ``` -------------------------------- ### Compile zstddec-stream.wasm Source: https://github.com/donmccurdy/zstddec-wasm/blob/main/README.md Compile the zstddeclib.c file into a WebAssembly module for streaming decoding. ```shell # build streaming wasm emcc zstddeclib.c -s EXPORTED_FUNCTIONS="['_ZSTD_decompress', '_ZSTD_findDecompressedSize', '_ZSTD_createDCtx', '_ZSTD_decompressStream', '_ZSTD_freeDCtx', '_ZSTD_DStreamInSize', '_ZSTD_DStreamOutSize', '_malloc', '_free']" -Wl,--no-entry -s WASM=1 -Oz -g0 -flto -s ALLOW_MEMORY_GROWTH=1 -s FILESYSTEM=0 -s STANDALONE_WASM=1 -DNDEBUG=1 -s PURE_WASI=0 -o zstddec-stream.wasm ``` -------------------------------- ### Encode WASM to Base64 Source: https://github.com/donmccurdy/zstddec-wasm/blob/main/README.md Encode the compiled WebAssembly files into base64 format for embedding. ```shell # encode WASM to base64 base64 -i zstddec.wasm > zstddec.txt base64 -i zstddec-stream.wasm > zstddec-stream.txt ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.