https://github.com/upupming/arithmetic-coding
:wrench: Arithmetic coding algorithm implemented in Node.js, both API and CLI support. 算术编码 npm 包,支持 API 调用和 CLI。
https://github.com/upupming/arithmetic-coding
arithmetic-coding compress compression lossless-compression-algorithm
Last synced: 4 months ago
JSON representation
:wrench: Arithmetic coding algorithm implemented in Node.js, both API and CLI support. 算术编码 npm 包,支持 API 调用和 CLI。
- Host: GitHub
- URL: https://github.com/upupming/arithmetic-coding
- Owner: upupming
- License: mit
- Created: 2019-03-28T14:48:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-31T11:26:33.000Z (over 6 years ago)
- Last Synced: 2025-08-09T01:37:45.381Z (4 months ago)
- Topics: arithmetic-coding, compress, compression, lossless-compression-algorithm
- Language: JavaScript
- Homepage:
- Size: 749 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README-zh.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# arithmetic-coding
- [英文文档](./README.md)
- 中文文档
## 安装
安装为模块供 API 调用:
```js
npm i arithmetic-coding
```
或者全局安装为命令行界面:
```js
npm i -g arithmetic-coding
```
## API
通过指定文件目录调用:
```js
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` 调用:
```js
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}`);
```
## 命令行界面
```js
$ ari-coding -h
Usage: index [options] [command]
Options:
-v, --version output the version number
-h, --help output usage information
Commands:
encode|e [options] encode a file
decode|d [options] decode a file
$ ari-coding encode -h
Usage: encode|e [options]
encode a file
Options:
-o, --output output file path
-h, --help output usage information
```
## 性能
您可以查看 [travis 测试日志](https://travis-ci.com/upupming/arithmetic-coding) 得知最新版本的运行时间。
一些运行测试结果如下:
| 文件大小 (字节) | 总运行时间 | 编码时间 | 解码时间 |
| --------------- | ---------- | -------- | -------- |
| 60640 | 110ms | 极小 | 110ms |
| 2130640 | 2940ms | 426ms | 2514ms |
## 关于算数编码算法
1. [维基百科](https://en.wikipedia.org/wiki/Arithmetic_coding)
2. [编码/解码的实际可用的实现](http://www.drdobbs.com/cpp/data-compression-with-arithmetic-encodin/240169251)
3. [GitHub 上 Reference-arithmetic-coding 的源代码](https://github.com/nayuki/Reference-arithmetic-coding)