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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bitfield-rle

v2.2.1

Published

A run-length-encoder that compresses bitfields.

Downloads

7,239

Readme

bitfield-rle

A run-length-encoder (RLE) that compresses bitfields.

npm install bitfield-rle

build status

Usage

var rle = require('bitfield-rle')
var bitfield = require('bitfield')

var bits = bitfield(1024)

bits.set(400, true) // set bit 400

var enc = rle.encode(bits.buffer) // rle encode the bitfield
console.log(enc.length) // 6 bytes
var dec = rle.decode(enc) // decode the rle encoded buffer
console.log(dec.length) // 128 bytes (like the old bitfield)

bits = bitfield(dec)
console.log(bits.get(400)) // still returns true

The encoder uses a compact format and will only run length encode sequences of bits if it compresses the bitfield. The encoded bitfield should therefore always be smaller or the same size as the original bitfield with the exception of a 1-6 byte header.

Since this uses run-length-encoding, you'll get the best compression results if you have longer sequences of the same bit in your bitfield.

API

The API is abstract-encoding compliant

buffer = rle.encode(bitfield, [buffer], [offset])

Run-length-encode a bitfield. Optionally you can pass in a buffer to encode it to.

length = rle.encodingLength(bitfield)

Returns how many bytes are needed to encode the bitfield

bitfield = rle.decode(buffer, [offset])

Decode an encoded bitfield.

length = rle.decodingLength(buffer, [offset])

Returns how many bytes a decoded bitfield will use.

Format

The encoded bitfield is a series of compressed and uncompressed bit sequences. All sequences start with a header that is a varint.

If the last bit is set in the varint (it is an odd number) then a header represents a compressed bit sequence.

compressed-sequence = varint(byte-length-of-sequence << 2 | bit << 1 | 1)

If the last bit is not set then a header represents an non compressed sequence

uncompressed-sequence = varint(byte-length-of-bitfield << 1 | 0) + (bitfield)

License

MIT