This project is part of the @thi.ng/umbrella monorepo.
Binary range encoder / decoder, based on Java implementation by Joe Halliwell.
STABLE - used in production
- @thi.ng/bitstream - ES6 iterator based read/write bit streams with support for variable word widths
- @thi.ng/rle-pack - Binary run-length encoding packer w/ flexible repeat bit widths
yarn add @thi.ng/range-coder
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/range-coder?module" crossorigin></script>
// UMD
<script src="https://unpkg.com/@thi.ng/range-coder/lib/index.umd.js" crossorigin></script>
Package sizes (gzipped, pre-treeshake): ESM: 670 bytes / CJS: 725 bytes / UMD: 762 bytes
import * as rc "@thi.ng/range-coder";
// 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 = rc.encodeBytes(src);
packed.length
// 146
packed.length/src.length
// 0.142578125
// unpack
dest = rc.decodeBytes(packed);
Karsten Schmidt
© 2017 - 2020 Karsten Schmidt // Apache Software License 2.0