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.
Wrapper for ArrayBuffer
s with support for bit-level reads and writes.
Similar to JavaScript's DataView.
+ 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
Length of this view (in bits) from the start of its buffer.
Underlying buffer which this view accesses.
Length of this view (in bytes) from the start of its buffer.
Returns the bit value at the specified bit offset.
Returns a bits
long value at the specified bit offset.
Returns a bits
long array of bit values at the specified bit offset.
Returns a buffer containing the bytes at the specified bit offset.
Returns a string decoded from the bytes at the specified bit offset.
Writes the bit value at the specified bit offset.
Writes a bits
long value at the specified bit offset.
remarks
There is no difference between signed and unsigned values when storing.
Writes a bits
long array of bit values at the specified bit offset.
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 0
s.
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
.
Wrapper for BitViews that maintains an index while reading/writing sequential data.
+ 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
Current position of this stream (in bits) from/to which data is read/written.
Length of this stream (in bits) from the start of its buffer.
Underlying buffer which this stream accesses.
Length of this stream (in bytes) from the start of its buffer.
Readonly
view: BitView
Underlying view which this stream accesses.
• get bitsLeft(): number
Number of bits remaining in this stream's underlying buffer from the current position.
Returns: number
• 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
Alias for bitIndex
Parameters:
Name | Type |
---|---|
val |
number |
Returns: void
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
.