长春快克
这个箱子生成 网络大会 约束 快递CDC 内容定义了切换库.
为节点使用安装
npm install @dstanesc/wasm-chunking-fastcdc-node
安装用于捆绑器
npm install @dstanesc/wasm-chunking-fastcdc-webpack
用法类型脚本
//import { compute_chunks } from "@dstanesc/wasm-chunking-fastcdc-node"
import { compute_chunks } from "@dstanesc/wasm-chunking-fastcdc-webpack"
const buf: Uint8Array = ...
// chunking spec: min_size 16 KB, avg size 32 KB, max size 64 KB
const offsets: Uint32Array = compute_chunks(buf, 16384, 32768, 65536)
瓦斯建造要求
建筑
wasm-pack build --out-dir pkg/webpack --out-name chunking --target bundler --scope dstanesc
wasm-pack build --out-dir pkg/node --out-name chunking --target nodejs --scope dstanesc
瓦斯测试
交互模式, 例如检查控制台中调试信息
wasm-pack test --firefox
无头模式
wasm-pack test --headless --firefox
本地使用的包装
npm pack pkg/node/
npm pack pkg/webpack/
烂API
函数为: compute chunks
pub fn compute_chunks(
source: &[u8],
min_size: u32,
avg_size: u32,
max_size: u32
) -> Result<Vec<u32>, RangeError>
从给定的一分块字节计算出块.
Min 大小指定了首选的最小块大小,最大 大小指定了首选的最大块大小;avg 大小是所期望的块"正常大小". 最小的可接受分数大小为64字节,同样为256字节和1024字节,分别表示avg 大小和最大 大小
A js sys: 当以上块规格超出范围时返回 RangeError .
示例
use wasm_chunking_fastcdc::compute_chunks;
let data: Vec<u8> = br"Lorem ipsum dolor sit amet, consectetur adipiscing elit...put more bits in here...".to_vec();
let slice: &[u8] = &data;
let min_size: u32 = 64;
let avg_size: u32 = 256;
let max_size: u32 = 1024;
let offsets: Vec<u32> = compute_chunks(slice, min_size, avg_size, max_size).unwrap();
许可证
任何许可 Apache 2.0 (英语) 或者说 麻省理工学院 随便你.