0.2.1 • Published 7 years ago

thing-rle-pack v0.2.1

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
7 years ago

thi.ng/rle-pack

Overview

Binary run-length encoding packer/unpacker w/ flexible repeat bit widths. Written in TypeScript, distributed in ES6.

Encoding format:

  • 32 bits - original size in bytes (header)

Then per value:

  • 1 bit - encoding flag (1 = RLE encoded, 0 = single occurrence)
  • 8 bits - value

The following is only used for repeated values:

  • 2 bits - repeat class
  • 3/4/8/16 bits - repeat count - 1 (if > 0x10000 then split into chunks...)
RepeatsOriginal (bits)RLE (bits)Saving (bits)Ratio
181+8-11.125
2161+8+2+320.875
3241+8+2+3100.583
4321+8+2+3180.438
8641+8+2+3500.219
9721+8+2+4570.208
161281+8+2+41130.117
171361+8+2+81170.14
25620481+8+2+820290.0093
25720561+8+2+1620290.013
51240961+8+2+1640690.0066
102481921+8+2+1681650.0033
655365242881+8+2+165242610.000051

Installation

npm i thing-rle-pack

API

let rle = require("thing-rle-pack");
// prepare dummy data
src = new Uint8Array(1024);
src.set([1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,4,4,3,3,3,2,2,2,2,1,1,1,1,1], 512);

// pack data
packed = rle.encodeBytes(src);
// Uint8Array [0,0,4,0,128,96,63,240,18,64,135,3,20,16,32,88,32,96,98,129,14,2,72,6,3,196]
 
packed.length
// 26 => 2.5% of original

// unpack
dest = rle.decodeBytes(packed);

Building

Build requirements

Building & testing this project requires Typescript 2.1+ and Mocha globally installed:

npm i typescript mocha -g
cd thing-bitstream
npm up
npm run build

Testing

TODO

npm link mocha
npm run test

Authors

  • Karsten Schmidt

License

Apache Software License 2.0