1.0.6 • Published 6 years ago

bitbuff v1.0.6

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

bitbuff

A binary buffer for storing and manipulating bits

Installation

npm i --save bitbuff
npm i bitbuff -g

Usage

var buffer = new BitBuffer(10 * 8); // 10 bytes

// Write the value 14 to the first 4 bits
buffer.write(14, 4);

// Set the value starting at bit 5 consuming a furthur 8 bits
buffer.set(252, 5, 8);

// Skip a few bits
buffer.skip(3);

// Seek to a bit position
buffer.seek(0);

// Read 4 bits from the buffer
var value1 = buffer.read(4); // value 14

// Read bits at an offset
var value2 = buffer.get(4, 8); // value 252

// Reset the position
buffer.reset();

// Clear the backing buffer with a zero pass
buffer.clear();

Or can be chained together

var buffer = new BitBuffer(5 * 8); // 5 bytes

buffer
  .write(3, 2)
  .write(12, 5)
  .write(222, 8)
  .skip(3);
  
var value1 = buffer
  .seek(7)
  .read(8) // value 222
1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago