@foxglove/wasm-lz4 (英语)
https://github.com/lz4/lz4 请检查isbn=值 (帮助) 编译为 Web Assembly 。 目前只支持去压抑. 公关欢迎!
API 密码
wasm-lz4 导出一个函数 :
export default (buffer: Buffer, destinationByteSize: number) => Buffer;
以下是使用模块的例子:
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 从服务器侧取,以便编译它。 有一个 说明文件中的更多信息。 。 。 .
用 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);
}
地方发展
- 运行
npm install以安装依赖. - 运行
npm run build在 Docker 容器内引用 emcc 并编译代码wasm-lz4.c以及所需的lz4源文件。 输出将会在dist/在主机上. - 运行
npm test进行测试.
许可证
@foxglove/wasm-lz4 获得许可 MIT 许可证。 。 。 .
释放
- 运行
yarn version --[major|minor|patch]切换到凸起版本 - 运行
git push && git push --tags以驱动新标签 - GitHub 动作会照顾剩下的
保持联系
加入我们 黑频道 问问题 分享反馈 随时了解我们团队的工作.