# @foxglove/wasm-zstd 中文文档

规范地址：https://npmcn.com/package/%40foxglove/wasm-zstd/

版本：1\.0\.1
npm 元数据更新时间：2023-02-08T23:15:55.067Z
中文译文更新时间：2026-11-15T10:39:32.224Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40foxglove/wasm-zstd
原文对照：https://npmcn.com/package/%40foxglove/wasm-zstd/?lang=original
项目主页：https://github.com/foxglove/wasm-zstd#readme
源码仓库：https://github.com/foxglove/wasm-zstd

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：432 kB，7 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2023-02-08T23:13:17.150Z
- 最新版本发布：2023-02-08T23:15:54.945Z
- 近 30 天下载量：231255（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

[https://github.com/facebook/zstd (中文(简体) )](https://github.com/facebook/zstd) 编译为WebAssembly,并作为高级TypeScript/JavaScript API被曝光. 公关欢迎!

## 安装

```sh
npm install @foxglove/wasm-zstd
```

也可以使用：`pnpm add @foxglove/wasm-zstd`、`yarn add @foxglove/wasm-zstd`、`bun add @foxglove/wasm-zstd`

## README

# @foxglove/wasm-zstd (英语)

[https://github.com/facebook/zstd (中文(简体) )](https://github.com/facebook/zstd) 编译为WebAssembly,并作为高级TypeScript/JavaScript API被曝光. 公关欢迎!

## API 密码

`@foxglove/wasm-zstd` 输出 :

```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;
```

以下是用这个库压缩后解压的例子:

```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);
}
```

## 使用浏览器中的模块

编译的网络大会模块分为两个部分:a `.js` 边和 a `.wasm` 边 在浏览器中 `.js` 侧面需要下载 `.wasm` 从服务器侧取,以便编译它。 有一个 [说明文件中的更多信息](https://kripken.github.io/emscripten-site/docs/compiling/Deploying-Pages.html)。 。 。 .

## 地方发展

1.  运行 `yarn install` 以安装依赖.
2.  运行 `yarn build` 在 Docker 容器内引用 emcc 并编译代码 `wasm-zstd.c` 以及所需的zstd源文件。 输出将会在 `dist/` 在主机上.
3.  运行 `yarn test` 进行测试.

## 许可证

@foxglove/wasm-zstd 获得许可 [MIT 许可证](https://opensource.org/licenses/MIT)。 。 。 .

## 释放

1.  运行 `yarn version --[major|minor|patch]` 切换到凸起版本
2.  运行 `git push && git push --tags` 以驱动新标签
3.  GitHub 动作会照顾剩下的

## 保持联系

加入我们 [黑频道](https://foxglove.dev/join-slack) 问问题 分享反馈 随时了解我们团队的工作.

## 常见问题

### @foxglove/wasm-zstd 是什么？

https://github\.com/facebook/zstd \(中文\(简体\) \) 编译为WebAssembly,并作为高级TypeScript/JavaScript API被曝光\. 公关欢迎\!

### 如何安装 @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 和提交记录判断。

