- 英文文档
- 中文文档
安装为模块供 API 调用:
npm i arithmetic-coding
或者全局安装为命令行界面:
npm i -g arithmetic-coding
通过指定文件目录调用:
const ariCoding = require('arithmetic-coding');
// 从文件编码
ariCoding.encode(path.resolve('/txt/long.txt'), path.resolve('/txt/long-encoded.txt'));
// 从文件解码
ariCoding.decode(path.resolve('/txt/long-encoded.txt'), path.resolve('/txt/long-decoded.txt'));
通过传入 Buffer
调用:
let data = Buffer.from('Example data', 'utf8');
// 从 Buffer 编码
let encoded = encode.encodeFromBuffer(data);
console.log(`encoded = ${encoded}`);
// 从 Buffer 解码
let decoded = decode.decodeFromBuffer(encoded);
console.log(`decoded = ${decoded}`);
$ ari-coding -h
Usage: index [options] [command]
Options:
-v, --version output the version number
-h, --help output usage information
Commands:
encode|e [options] <file> encode a file
decode|d [options] <file> decode a file
$ ari-coding encode -h
Usage: encode|e [options] <file>
encode a file
Options:
-o, --output <file> output file path
-h, --help output usage information
您可以查看 travis 测试日志 得知最新版本的运行时间。
一些运行测试结果如下:
文件大小 (字节) | 总运行时间 | 编码时间 | 解码时间 |
---|---|---|---|
60640 | 110ms | 极小 | 110ms |
2130640 | 2940ms | 426ms | 2514ms |