# @foxglove/wasm-lz4 中文文档

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

版本：1\.0\.2
npm 元数据更新时间：2023-01-31T20:50:22.116Z
中文译文更新时间：2026-11-15T10:39:51.620Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：37.3 kB，7 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2023-01-31T20:50:21.684Z
- 最新版本发布：2023-01-31T20:50:21.956Z
- 近 30 天下载量：229770（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：1（近 12 个月 0 个）

## 中文简介

[https://github.com/lz4/lz4 请检查isbn=值 (帮助)](https://github.com/lz4/lz4) 编译为 Web Assembly 。 目前只支持去压抑. 公关欢迎!

## 安装

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

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

## README

# @foxglove/wasm-lz4 (英语)

[https://github.com/lz4/lz4 请检查isbn=值 (帮助)](https://github.com/lz4/lz4) 编译为 Web Assembly 。 目前只支持去压抑. 公关欢迎!

## API 密码

`wasm-lz4` 导出一个函数 :

```js
export default (buffer: Buffer, destinationByteSize: number) => Buffer;
```

以下是使用模块的例子:

```js
import fs from "fs";
import decompress from "wasm-lz4";

const compressedBytes = fs.readFileSync("compressed.lz4");

// currently you need to know the exact expected size of the output buffer
// so the wasm runtime can allocate enough bytes to decompress into
// TODO: this should not be necessary...it's exposed in the lz4 C code
const outputBytes = compressedBytes * 10;
const decompressedBytes = decompress(compressedBytes, outputBytes);
```

## 使用浏览器中的模块

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

### 用 Web 包装

我们要求 `wasm-lz4.wasm` 模块 `locateFile` 定义,这样可以将模块与动态路径捆绑在一起。 因此,如果您使用Webpack,您可以添加以下条目:

```
...
rules : [
  ...
  {
    test: /\.wasm$/,
    type: "javascript/auto",
    use: {
      loader: "file-loader",
      options: {
        name: "[name]-[hash].[ext]",
      },
    },
  },
  ...
]
...
```

这个 `javascript/auto` 类型设置告诉 Webpack 绕过默认的导入逻辑,而只是将文件导入为-is。 希望这个黑客能在网络包装中获得更好的WebAssembly支持而消失.

## 同步装入和编译

之后 `.wasm` 二进制已装入( 通过 `fetch` 在浏览器中或 `require` 它必须在WebAssembly运行时编译。 如果你打电话 `decompress` 在它完成编译之前,它将会出现一个错误,表明它还没有准备好. 等待模块被装入时,您可以做如下一些事情:

```
import decompress from 'wasm-lz4'

async function doWork() {
  await decompress.isLoaded;
  decompress(buffer, outputByteLength);
}
```

## 地方发展

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

## 许可证

@foxglove/wasm-lz4 获得许可 [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-lz4 是什么？

https://github\.com/lz4/lz4 请检查isbn=值 \(帮助\) 编译为 Web Assembly 。 目前只支持去压抑\. 公关欢迎\!

### 如何安装 @foxglove/wasm-lz4？

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

### @foxglove/wasm-lz4 支持 TypeScript 吗？

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

### @foxglove/wasm-lz4 支持 ESM 还是 CommonJS？

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

### @foxglove/wasm-lz4 可以商用吗？

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

### @foxglove/wasm-lz4 的下载量有多少？

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

### @foxglove/wasm-lz4 还在维护吗？

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

