npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thi.ng/rle-pack

v3.2.3

Published

Binary run-length encoding packer w/ flexible repeat bit widths and a naive RLE encoder/decoder for arrays of arbitrary typed values

Readme

@thi.ng/rle-pack

npm version npm downloads Mastodon Follow

[!NOTE] This is one of 214 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

About

The package provides two approaches for Run-length encoding/decoding:

Simple RLE

The naive approach operates on arrays of arbitrary values and supports user-defined predicates to determine if a consecutive input values are equal (i.e. repeated). By default uses === strict comparison.

import { encodeSimple, decodeSimple } from "@thi.ng/rle-pack";

const src = [..."aaaaaabbbbaaaxyxxx"];

const encoded = encodeSimple(src);
console.log(encoded);
// ["a", 6, "b", 4, "a", 3, "x", 1, "y", 1, "x", 3]

const decoded = decodeSimple(encoded);
console.log(decoded);
// ["a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "a", "a", "a", "x", "y", "x", "x", "x"]

Binary encoding

Binary run-length encoding packer/unpacker with support for customizable input word sizes (1 - 32 bits) and repeat count (run-length) bit sizes (1 - 16 bits). The encoder uses 4 different repeat group sizes (thresholds) to minimize the number of bits used to store the run lengths. The range of supported run lengths is 16 bits (i.e. 65536 repetitions). If a value is repeated more often than that, the remainder will be encoded using additional RLE chunks...

Encoding format

data layout

  • 32 bits - original number of words
  • 5 bits - word size
  • 16 bits - 4x RLE repeat group / chunk sizes (in bits)

The default group sizes are: 3, 4, 8, 16, i.e. 8, 16, 256, 65536 repetitions

Then per value:

  • 1 bit - encoding flag (1 = RLE encoded, 0 = single occurrence)
  • 2 bits - repeat or chunk class ID
  • m bits - repeat count or chunk size (if greater than max group size then split into chunks...)
  • n bits - value(s)

Code example

import { encodeBinary, decodeBinary } from "@thi.ng/rle-pack";

// prepare dummy data
const 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
const packed = encodeBinary(src, src.length);
console.log(packed.length);
// 30 => 2.93% of original

// pack with custom word size (3 bits, i.e. our value range is only 0-7)
// and use custom repeat group sizes suitable for our data
const alt = encodeBinary(src, src.length, 3, [1, 2, 3, 9]);
console.log(alt.length);
// 20 => 1.95% of original, 66% of default config

// unpack
const unpacked = decodeBinary(alt);
console.log(unpacked.length);

Status

STABLE - used in production

Search or submit any issues for this package

Related packages

  • @thi.ng/binary - 100+ assorted binary / bitwise operations, conversions, utilities, lookup tables
  • @thi.ng/bitstream - ES6 iterator based read/write bit streams with support for variable word widths
  • @thi.ng/range-coder - Binary data range encoder / decoder

Installation

yarn add @thi.ng/rle-pack

ESM import:

import * as rle from "@thi.ng/rle-pack";

Browser ESM import:

<script type="module" src="https://esm.run/@thi.ng/rle-pack"></script>

JSDelivr documentation

For Node.js REPL:

const rle = await import("@thi.ng/rle-pack");

Package sizes (brotli'd, pre-treeshake): ESM: 802 bytes

Dependencies

Note: @thi.ng/api is in most cases a type-only import (not used at runtime)

API

Generated API docs

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-rle-pack,
  title = "@thi.ng/rle-pack",
  author = "Karsten Schmidt",
  note = "https://thi.ng/rle-pack",
  year = 2017
}

License

© 2017 - 2026 Karsten Schmidt // Apache License 2.0