# @thewtex/zstddec

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

Latest version **0.2.1** (published 2024-04-19) · MIT AND BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install @thewtex/zstddec
pnpm add @thewtex/zstddec
yarn add @thewtex/zstddec
bun add @thewtex/zstddec
```

## Health

**Score 45/100 (D)** — status: abandoned.

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

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2024-04-19 |
| First published | 2023-09-06 |
| Weekly downloads | 0 |
| License | MIT AND BSD-3-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 352.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 73 |
| Author | Don McCurdy |
| Maintainers | thewtex |
| Keywords | zstd, zstandard, compression |

## Links

- npm: https://www.npmjs.com/package/@thewtex/zstddec
- Repository: https://github.com/donmccurdy/zstddec
- Homepage: https://github.com/donmccurdy/zstddec#readme
- Issues: https://github.com/donmccurdy/zstddec/issues
- npm.io page: https://npm.io/package/@thewtex/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.2.1 (latest) — 2024-04-19
- 0.2.0 — 2023-10-26
- 0.1.2 — 2023-09-06
- 0.1.1 — 2023-09-06
- 0.1.0 — 2023-09-06

## README

# zstddec

[![Latest NPM release](https://img.shields.io/npm/v/zstddec.svg)](https://www.npmjs.com/package/zstddec)
[![Minzipped size](https://badgen.net/bundlephobia/minzip/zstddec)](https://bundlephobia.com/result?p=zstddec)
[![Build Status](https://github.com/donmccurdy/zstddec/workflows/build/badge.svg?branch=main&event=push)](https://github.com/donmccurdy/zstddec/actions?query=workflow%3Abuild)

[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:

```
npm install
npm run dist
```

To test changes:

```
npm test
```

## Building from source

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

```shell
./create_single_file_decoder.sh
```

> **Note**
The current build is based on zstd v1.5.0. The binary sized increased
following this version.

```shell
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
base64 -w 0 zstddec.wasm > zstddec.txt
```

> **Note**
The `-w 0` argument is only for the `base64` shipped on Linux systems -- on macOS this should be omitted.

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.

## 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/@thewtex/zstddec · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
