@foxglove/wasm-zstd (英语)
https://github.com/facebook/zstd (中文(简体) ) 编译为WebAssembly,并作为高级TypeScript/JavaScript API被曝光. 公关欢迎!
API 密码
@foxglove/wasm-zstd 输出 :
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;
以下是用这个库压缩后解压的例子:
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 从服务器侧取,以便编译它。 有一个 说明文件中的更多信息。 。 。 .
地方发展
- 运行
yarn install以安装依赖. - 运行
yarn build在 Docker 容器内引用 emcc 并编译代码wasm-zstd.c以及所需的zstd源文件。 输出将会在dist/在主机上. - 运行
yarn test进行测试.
许可证
@foxglove/wasm-zstd 获得许可 MIT 许可证。 。 。 .
释放
- 运行
yarn version --[major|minor|patch]切换到凸起版本 - 运行
git push && git push --tags以驱动新标签 - GitHub 动作会照顾剩下的
保持联系
加入我们 黑频道 问问题 分享反馈 随时了解我们团队的工作.