arithmetic-coding
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');
ariCoding.encode(__dirname + '/txt/long.txt', __dirname + '/txt/long-encoded.txt');
ariCoding.decode(__dirname + '/txt/long-encoded.txt', __dirname + '/txt/long-decoded.txt');
From Buffer
:
let data = Buffer.from('Example data', 'utf8');
let encoded = encode.encodeFromBuffer(data);
console.log(`encoded = ${encoded}`);
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
About the algorithm
- Wikipedia
- How to implement practical encoder/decoder
- Reference-arithmetic-coding on GitHub