# zstddec

> ZSTD (Zstandard) decoder for Web and Node.js, using WebAssembly

Latest version **0.3.1** (published 2026-09-05) · MIT AND BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install zstddec
pnpm add zstddec
yarn add zstddec
bun add zstddec
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2026-09-05 |
| First published | 2020-07-27 |
| Weekly downloads | 0 |
| License | MIT AND BSD-3-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 333.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Don McCurdy <dm@donmccurdy.com> |
| Maintainers | donmccurdy |
| Keywords | zstd, zstandard, compression |

## Links

- npm: https://www.npmjs.com/package/zstddec
- Repository: github:donmccurdy/zstddec
- npm.io page: https://npm.io/package/zstddec

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 0.3.1 (latest) — 2026-09-05
- 0.2.0-alpha.4 (alpha) — 2026-01-03
- 0.2.0 — 2026-01-08
- 0.2.0-alpha.3 — 2025-06-07
- 0.1.0 — 2023-09-18
- 0.0.2 — 2020-07-27
- 0.0.1 — 2020-07-27

## README

# zstddec

[![Latest NPM release](https://img.shields.io/npm/v/zstddec.svg)](https://www.npmjs.com/package/zstddec)
[![Build Status](https://github.com/donmccurdy/zstddec/actions/workflows/ci.yml/badge.svg)](https://github.com/donmccurdy/zstddec/actions?query=workflow%3Abuild+branch%3Amain)

[ZSTD (Zstandard)](https://github.com/facebook/zstd) decoder for Web and Node.js, using WebAssembly.

## Installation

```shell
npm install --save zstddec
```

## API

```javascript
import { ZSTDDecoder } from 'zstddec';

const decoder = new ZSTDDecoder();

await decoder.init();

const decompressedArray = decoder.decode( compressedArray, uncompressedSize );
```

> **Limitations:** The decoder may fail with the error `wasm function signature contains illegal type` when the `uncompressedSize` is not known in advance and given to the `decode()` method. This is presumably a bug in the WASM bindings, which I am not yet sure how to fix.

## Contributing

To build the project locally, run:

```
yarn install
yarn build
```

To test changes:

```
yarn test
```

## Building from source

Compiled from https://github.com/facebook/zstd/tree/dev/build/single_file_libs, with the
following steps:

```shell
# build zstd
make
cd build/single_file_libs
./create_single_file_decoder.sh

# 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

# 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
base64 -i zstddec.wasm > zstddec.txt
base64 -i zstddec-stream.wasm > zstddec-stream.txt
```

The base64 string written to `zstddec.txt` is embedded as the `wasm` variable at the bottom
of the source file. The rest of the file is written by hand, in order to avoid an additional JS
wrapper generated by Emscripten.

_Last built June 2025, zstd v1.5.7 (`f8745da6`), emscc v4.0.10_.

## License

JavaScript wrapper is provided under the MIT License, and the WASM ZSTD decoder is provided by Facebook under the BSD 3-Clause License.

---
_Source: https://npm.io/package/zstddec · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
