bit-buffers
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

bit-buffers

A simple bit buffer (bit-string) implementation with base64 zlib compressed bitstring support.

Usage

import { BitBuffer } from "bit-buffers"

// BitBuffers are immutable and default to 16kb capacity by default.
const bits = new BitBuffer()

// To create a smaller BitBuffer, you can pass in a smaller capacity, for
// example this will create a BitBuffer with 16 bytes:
// const smallerBits = new BitBuffer(16 * 8)

// set bit 7 to 1.
const bits2 = bits.set(7) // => bits
bits2.test(7) // => true

// unset bit 7 to 0
const bits3 = bits2.unset(7) // => bits
bits3.test(7) // => false

const bits4 = bits3.set(3)
const bitstring = bits4.toBitstring() // => "eJwTYEAFAAEQABE="

const bits5 = BitBuffer.fromBitstring(bitstring)
bits5 === bits4 // true
const indexArray = bits5.toIndexArray() // => [3]

const bits6 = BitBuffer.fromIndexArray(indexArray)
bits6 === bits5 // => true

Building

npm run build

Testing

npm test

Linting

npm run lint

Type-checking

npm run type-check

Brought to you by M2 Labs

M2 Labs

This project is maintained and funded by M2 Labs, a Web3 product development studio.

Readme

Keywords

none

Package Sidebar

Install

npm i bit-buffers

Weekly Downloads

21

Version

1.0.2

License

ISC

Unpacked Size

10.8 kB

Total Files

5

Last publish

Collaborators

  • venables