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 🙏

© 2025 – Pkg Stats / Ryan Hefner

bit-buffer-ts

v0.8.1

Published

Bit-level reads and writes for Uint8Arrays and Node.js Buffers

Readme

@ntrip/bit-buffer

Modification of the original bit-buffer by inolen, changing to TypeScript and modifying methods relating to buffer/string reading/writing.

BitBuffer provides two objects, BitView and BitStream. BitView is a wrapper for ArrayBuffers with support for bit-level reads and writes. BitStream is a wrapper for a BitView used to help maintain your current buffer position.

Class: BitView

Wrapper for ArrayBuffers with support for bit-level reads and writes.

Similar to JavaScript's DataView.

Constructors

constructor

+ new BitView(buffer: Uint8Array, byteOffset: number, byteLength: number): BitView

Parameters:

Name | Type | Default | ------ | ------ | ------ | buffer | Uint8Array | - | byteOffset | number | 0 | byteLength | number | buffer.length - byteOffset |

Returns: BitView

Properties

Readonly bitLength: number

Length of this view (in bits) from the start of its buffer.


Readonly buffer: Uint8Array

Underlying buffer which this view accesses.


Readonly byteLength: number

Length of this view (in bytes) from the start of its buffer.

Methods

getBit(offset: number): 1 | 0

Returns the bit value at the specified bit offset.


getBits(offset: number, bits: number, signed: boolean): number

Returns a bits long value at the specified bit offset.


getBitArray(offset: number, bits: number): boolean[]

Returns a bits long array of bit values at the specified bit offset.


readBuffer(offset: number, byteLength: number): Uint8Array

Returns a buffer containing the bytes at the specified bit offset.


readString(offset: number, byteLength: number, decoder?: undefined | TextDecoder): string

Returns a string decoded from the bytes at the specified bit offset.


setBit(offset: number, value: 1 | 0): void

Writes the bit value at the specified bit offset.


setBits(offset: number, value: number, bits: number): void

Writes a bits long value at the specified bit offset.

remarks There is no difference between signed and unsigned values when storing.


setBitArray(offset: number, value: boolean[], bits: number): void

Writes a bits long array of bit values at the specified bit offset.


writeBuffer(offset: number, buffer: Uint8Array): number

Writes the contents of a buffer at the specified bit offset.

Returns: The number of bytes written.


writeString(offset: number, string: string, byteLength?: undefined | number, encoder?: undefined | TextEncoder): number

Writes an encoded form of a string to the bytes at the specified bit offset.

remarks If the encoded string length is less than byteLength, the remainder is filled with 0s.

remarks If the encoded string length is longer than byteLength, it is truncated.

Returns: The number of bytes written (may be different from the string length).


getBoolean, getInt8, getInt16, getInt32, getUint8, getUint16, getUint32, setBoolean, setInt8, setInt16, setInt32, setUint8, setUint16, setUint32

Helper methods, see getBits and setBits.

Class: BitStream

Wrapper for BitViews that maintains an index while reading/writing sequential data.

Constructors

constructor

+ new BitStream(source: BitView): BitStream

Parameters:

Name | Type | ------ | ------ | source | BitView |

Returns: BitStream

+ new BitStream(source: Buffer, byteOffset?: undefined | number, byteLength?: undefined | number): BitStream

Parameters:

Name | Type | ------ | ------ | source | Buffer | byteOffset? | undefined | number | byteLength? | undefined | number |

Returns: BitStream

Properties

bitIndex: number

Current position of this stream (in bits) from/to which data is read/written.


Readonly bitLength: number

Length of this stream (in bits) from the start of its buffer.


Readonly buffer: Uint8Array

Underlying buffer which this stream accesses.


Readonly byteLength: number

Length of this stream (in bytes) from the start of its buffer.


Readonly view: BitView

Underlying view which this stream accesses.

Accessors

bitsLeft

get bitsLeft(): number

Number of bits remaining in this stream's underlying buffer from the current position.

Returns: number


byteIndex

get byteIndex(): number

Current position of this stream (in bytes) from/to which data is read/written.

Returns: number

set byteIndex(val: number): void

Current position of this stream (in bytes) from/to which data is read/written.

Parameters:

Name | Type | ------ | ------ | val | number |

Returns: void


index

Alias for bitIndex

Parameters:

Name | Type | ------ | ------ | val | number |

Returns: void

Methods

readBit(): 1 | 0


readBits(bits: number, signed: boolean): number


readBitArray(bits: number): boolean[]


readBuffer(byteLength: number): Uint8Array


readString(byteLength: number, decoder?: undefined | TextDecoder): string


writeBit(value: 1 | 0): void


writeBits(value: number, bits: number): void


writeBitArray(value: boolean[], bits: number): void


writeBuffer(buffer: Uint8Array): number


writeString(string: string, byteLength?: undefined | number, encoder?: undefined | TextEncoder): number


readBoolean, readInt8, readInt16, readInt32, readUint8, readUint16, readUint32, writeBoolean, writeInt8, writeInt16, writeInt32, writeUint8, writeUint16, writeUint32

Helper methods, see readBits and writeBits.