@foxglove/wasm-zstd

中文文档
1.0.1发布于 2023/02/09MITTypeScriptCommonJS零依赖近 30 天下载 23.1万

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

原始使用文档
文档目录6 节
  1. API
  2. Using the module in a browser
  3. Developing locally
  4. License
  5. Releasing
  6. Stay in touch

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

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:

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.

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.

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 to ask questions, share feedback, and stay up to date on what our team is working on.

版本与发布记录

@foxglove/wasm-zstd 共发布 2 个版本,首次发布于 2023/02/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2023/02/093 年前
1.0.02023/02/093 年前

关于 @foxglove/wasm-zstd 的常见问题

@foxglove/wasm-zstd 是什么?

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

如何安装 @foxglove/wasm-zstd?

在项目目录运行 npm install @foxglove/wasm-zstd,或使用 pnpm add / yarn add / bun add。

@foxglove/wasm-zstd 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@foxglove/wasm-zstd 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@foxglove/wasm-zstd 可以商用吗?

@foxglove/wasm-zstd 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@foxglove/wasm-zstd 的下载量有多少?

根据 npm 官方下载统计,@foxglove/wasm-zstd 在 2026/10/16 – 2026/11/14 这 30 天内被下载 231,255 次,日均约 7,709 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@foxglove/wasm-zstd 还在维护吗?

最新版本 1.0.1 发布于 2023/02/09(3 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/02/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。