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

buffer-bits

v0.0.12

Published

This component is able to hold a set of bits (NOT bytes) and do operations on them. Could be used to analyze some protocol by yourself...

Downloads

4

Readme

buffer-bits

Build Status

This component is able to hold a set of bits (NOT bytes) and do operations on them. Could be used to analyze some protocol by yourself...

Quick Example

var Bits = require('buffer-bits');
var myBuffer = Buffer.from([20, 30, 40, 50]);

// starting from bit offset 3
// and capture 26 bits after
var myBits = Bits.from(myBuffer, 3, 26);    

console.log(myBits.toBinaryString());
// 0b10100000111100010100000110

Features

  1. Class Methods
    • Bits.from(buffer [, offset = 0 [, length = buffer.length << 3 ]])
      • create Bits from existing Buffer object
    • Bits.from(bits [, offset = 0 [, length = bits.length ]])
      • create Bits from existing Bits object
    • Bits.alloc(length)
      • create Bits with count of bits and filled with 0
  2. Constructor
    • new Bits(buffer, offset, length) *
      • there's NO params validating in this constructor, please DON'T use it for creating new instance...
  3. Properties (read-only)
    • length
      • count of the total bits
    • byteLength
      • total bytes the Bits object holds
    • isFullByte
      • return true if total bits count is a multiple of 8
    • buffer
      • inner Buffer object hold by Bits. Take care to NOT write to this buffer directly.
    • startOffset *
      • represents the start bit offset inside the byte. This property should be RARELY used, use it when you know what you're doing...
    • isLeftAligned *
      • represents if all the bits are left aligned in the inner buffer, RARELY
    • isRightAligned *
      • represents if all the bits are right aligned in the inner buffer, RARELY
  4. Methods
    • readInt()
      • read integer value of current bits (big endian)
    • readIntLE()
      • read integer value of current bits with little endian
    • readUInt()
      • read unsigned integer value of current bits (big endian)
    • readUIntLE()
      • read unsigned integer value of current bits with little endian
    • readString([encoding[, start[, end]]])
    • readBit(index)
      • read the bit value (1: true, 0: false) at position 'index'
    • setBit(index, value)
      • set the bit value (1: true, 0: false) at position 'index'
    • toggleBit(index)
      • toggle the bit value at position 'index', 1->0, 0->1
    • toggleAll()
      • toggle all the bits
    • concat(Bits)
      • create Bits by concating another Bits object
    • toBinaryString()
      • return a '0b<binaryData>' format string, like 0b110101010
    • equals(Bits)
      • return true if all bits equals to another Bits object
    • align(Boolean) *
      • align all the bits inside the inner buffer to the left(true) or right(false) side
    • alignLeft() *
      • align all the bits in the inner buffer to the left side
    • alignRight() *
      • align all the bits in the inner buffer to the right side

More Examples

console.log(myBits.length);
// 26

console.log(myBits.byteLength);
// 4

console.log(myBits.startOffset);
// 6

console.log(myBits.buffer);
// <Buffer 02 83 c5 06>

console.log(myBits.readInt());
// 42190086

console.log(myBits.readBit(20));
// false

myBits.setBit(20, true);
console.log(myBits.readBit(20));
// true

More More Examples

Please check the tests in test folder to see more details.

License

MIT