
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
bitfield-rle
Advanced tools
A run-length-encoder (RLE) that compresses bitfields.
npm install bitfield-rle
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.
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.
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)
MIT
FAQs
A run-length-encoder that compresses bitfields.
The npm package bitfield-rle receives a total of 3,096 weekly downloads. As such, bitfield-rle popularity was classified as popular.
We found that bitfield-rle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.