BitBuffer provides two objects, BitView and BitStream. BitView is a wrapper for ArrayBuffers, similar to JavaScript's DataView, but with support for bit-level reads and writes. BitStream is a wrapper for a BitView used to help maintain your current buffer position, as well as to provide higher-level read / write operations such as for ASCII strings.
BitView
Attributes
bb.buffer // Underlying ArrayBuffer.
bb.bigEndian = true; // Switch to big endian (default is little)
Default constructor, takes in a single argument of an ArrayBuffer. Optional are the and arguments to offset and truncate the view's representation of the buffer.
icewind1991
robin@icewind.nl
byteOffset
byteLength
getBits(offset, bits, signed)
Reads bits number of bits starting at offset, twiddling the bits appropriately to return a proper 32-bit signed or unsigned value. NOTE: While JavaScript numbers are 64-bit floating-point values, we don't bother with anything other than the first 32 bits.
Writes a string followed by a NULL character to the underlying view starting at the current index. If the string is longer than bytes it will be truncated, and if it is shorter 0x00 will be written in its place.
readBytes(size)
Read a size bytes into a new Uint8Array instance.
writeBytes(buffer, size)
Write size bytes from a given Uint8Array instance.