# @foxglove/wasm-zstd

> https://github.com/facebook/zstd compiled to WebAssembly and exposed as a high-level TypeScript/JavaScript API . PRs welcome!

Latest version **1.0.1** (published 2023-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @foxglove/wasm-zstd
pnpm add @foxglove/wasm-zstd
yarn add @foxglove/wasm-zstd
bun add @foxglove/wasm-zstd
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-02-08 |
| First published | 2023-02-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 422 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Maintainers | foxglovebot, amacneil |

## Links

- npm: https://www.npmjs.com/package/@foxglove/wasm-zstd
- Repository: https://github.com/foxglove/wasm-zstd
- Homepage: https://github.com/foxglove/wasm-zstd#readme
- Issues: https://github.com/foxglove/wasm-zstd/issues
- npm.io page: https://npm.io/package/@foxglove/wasm-zstd

## Recent versions

- 1.0.1 (latest) — 2023-02-08
- 1.0.0 — 2023-02-08

## README

# @foxglove/wasm-zstd

https://github.com/facebook/zstd compiled to WebAssembly and exposed as a high-level TypeScript/JavaScript API . PRs welcome!

## API

`@foxglove/wasm-zstd` exports:

```typescript
export const isLoaded: Promise<boolean>;
export function compressBound(size: number): number;
export function compress(buffer: Uint8Array, compressionLevel?: number): Buffer;
export function decompress(buffer: Uint8Array, size: number): Buffer;
```

Here is an example of compressing then decompressing with this library:

```js
import fs from "fs/promises";
import zstd from "@foxglove/wasm-zstd";

async function main() {
  const inputData = await fs.readFile("input.txt");

  // Wait for the wasm module to load
  await zstd.isLoaded;

  // Compress and save to a file with zstd compression level 3
  const compressedBytes = zstd.compress(inputData, 3);
  await fs.writeFile("compressed.zst", compressedBytes);

  // Currently you need to know the size of the output buffer so the wasm runtime
  // can allocate enough bytes to decompress into
  const outputSize = inputData.byteLength;

  // Decompress
  const decompressedBytes = zstd.decompress(compressedBytes, inputData.byteLength);
  assert(decompressedBytes.byteLength === inputData.byteLength);
}
```

## Using the module in a browser

Emscripten compiled WebAssembly modules are built in 2 parts: a `.js` side and a `.wasm` side. In the browser the `.js` side needs to download the `.wasm` side from the server so it can compile it. There is [more information available in the emscripten documentation](https://kripken.github.io/emscripten-site/docs/compiling/Deploying-Pages.html).

## Developing locally

1. Run `yarn install` to install dependencies.
2. Run `yarn build` to invoke emcc inside a Docker container and compile the code in `wasm-zstd.c` as well as the required zstd source files. The output will be in `dist/` on the host machine.
3. Run `yarn test` to run the tests.

## License

@foxglove/wasm-zstd is licensed under [MIT License](https://opensource.org/licenses/MIT).

## Releasing

1. Run `yarn version --[major|minor|patch]` to bump version
2. Run `git push && git push --tags` to push new tag
3. GitHub Actions will take care of the rest

## Stay in touch

Join our [Slack channel](https://foxglove.dev/join-slack) to ask questions, share feedback, and stay up to date on what our team is working on.

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