An open API service indexing awesome lists of open source software.

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。

Awesome Lists containing this project

README

          

# arithmetic-coding

npm
JavaScript Style Guide
Coveralls
travis build status
License

- [英文文档](./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)