Skip to content
🔧 Arithmetic coding algorithm implemented in Node.js, both API and CLI support. 算数编码 npm 包,支持 API 调用和 CLI。
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
docs/images
src
test
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
README-zh.md
README.md
package-lock.json
package.json

README.md

arithmetic-coding

npm JavaScript Style Guide Coveralls travis build status License

Installation

Install as module for API usage:

npm i arithmetic-coding

Or install as global CLI:

npm i -g arithmetic-coding

API

From file path:

const ariCoding = require('arithmetic-coding');
// Encode from file
ariCoding.encode(path.resolve('/txt/long.txt'), path.resolve('/txt/long-encoded.txt'));
// Decode from file
ariCoding.decode(path.resolve('/txt/long-encoded.txt'), path.resolve('/txt/long-decoded.txt'));

From Buffer:

let data = Buffer.from('Example data', 'utf8');
// Encode from Buffer
let encoded = encode.encodeFromBuffer(data);
console.log(`encoded = ${encoded}`);
// Decode from Buffer
let decoded = decode.decodeFromBuffer(encoded);
console.log(`decoded = ${decoded}`);

Command-line interface

$ 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

Performance

You can see the latest travis test for running time used by each test.

Some benchmarks are shown below:

File size (Bytes) total time encode time decode time
60640 110ms small 110ms
2130640 2940ms 426ms 2514ms

About the algorithm

  1. Wikipedia
  2. How to implement practical encoder/decoder
  3. Reference-arithmetic-coding on GitHub
You can’t perform that action at this time.