npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hpcc-js/wasm-zstd

v1.15.0

Published

hpcc-js - WASM zstd

Readme


title: Zstd description: WebAssembly wrapper for the Zstandard compression library outline: deep

@hpcc-js/wasm-zstd

This package provides a WebAssembly wrapper around the Zstandard library. This provides efficient compression and decompression of data.

Installation

::: code-group

npm install @hpcc-js/wasm-zstd
yarn add @hpcc-js/wasm-zstd
pnpm add @hpcc-js/wasm-zstd

:::

One-shot usage

import { Zstd } from "@hpcc-js/wasm-zstd";

const zstd = await Zstd.load();

//  Generate some "data"
const data = new Uint8Array(Array.from({ length: 100000 }, (_, i) => i % 256));

const compressed_data = zstd.compress(data);
const decompressed_data = zstd.decompress(compressed_data);

decompress() uses a fast path when the frame records its content size. Frames with unknown content size (streaming compressors, stdin, many network streams) automatically fall back to the safe streaming decoder—no output-size guessing is required.

Streaming compression

import { Zstd } from "@hpcc-js/wasm-zstd";

const zstd = await Zstd.load();
zstd.resetCompression(3);

const parts: Uint8Array[] = [];
parts.push(zstd.compressChunk(chunk1)); // may be empty while Zstd buffers input
parts.push(zstd.compressChunk(chunk2));
parts.push(zstd.compressEnd());

Streaming decompression

import { Zstd } from "@hpcc-js/wasm-zstd";

const zstd = await Zstd.load();
zstd.resetDecompression();

const parts: Uint8Array[] = [];
parts.push(zstd.decompressChunk(compressedChunk1)); // may be empty
parts.push(zstd.decompressChunk(compressedChunk2));
zstd.decompressEnd(); // throws if the final frame is truncated

Call decompressEnd() after the last chunk. Intermediate empty output is valid and does not mean the frame is complete. Corrupt or truncated input throws an Error that includes the operation name and Zstandard error name when available.

Workers

Use the default package entry from browser module workers or Node.js worker threads. The WASM payload is embedded in the bundled JavaScript, so there is no separate .wasm file to copy or URL to pass to Zstd.load().

Browser module worker

import { Zstd } from "@hpcc-js/wasm-zstd";

self.onmessage = async function (e: MessageEvent<Uint8Array>) {
  const zstd = await Zstd.load();
  const compressed = zstd.compress(e.data);
  const decompressed = zstd.decompress(compressed);

  self.postMessage(decompressed);
};
const worker = new Worker(new URL("./worker.ts", import.meta.url), {
  type: "module",
});

worker.onmessage = function (e: MessageEvent<Uint8Array>) {
  console.log(e.data);
};

worker.postMessage(data);

Node.js worker thread

import { parentPort } from "node:worker_threads";
import { Zstd } from "@hpcc-js/wasm-zstd";

parentPort?.on("message", async function (data) {
  const zstd = await Zstd.load();
  const compressed = zstd.compress(data);
  const decompressed = zstd.decompress(compressed);

  parentPort?.postMessage(decompressed);
});
import { Worker } from "node:worker_threads";

const worker = new Worker(new URL("./worker.js", import.meta.url));

worker.on("message", function (data: Uint8Array) {
  console.log(data);
});

worker.postMessage(data);

Singleton / serialization warning

Zstd.load() returns a singleton within the current JavaScript context. Compression and decompression contexts are stateful. Callers must serialize streaming operations on the shared instance—do not interleave concurrent streams on the same Zstd object. Prefer resetCompression() / resetDecompression() over the legacy reset() so one context is not cleared accidentally with the other.

Reference