iobuffer
Read and write binary data in ArrayBuffers
Installation
$ npm install iobuffer
API
Buffer
InputBuffer
and OutputBuffer
both inherit from Buffer
which defines the following interface:
buffer
Reference to the internal ArrayBuffer
object.
length
Byte length of the internal ArrayBuffer
object.
available(byteLength = 1)
Returns true
if there are enough bytes between the current offset and the buffer's end, false otherwise.
setBigEndian() / setLittleEndian()
Set the endianess for multi-byte values (default is little endian).
isBigEndian() / isLittleEndian()
Returns a boolean indicating if current endianess matches.
littleEndian
true
if current endianess is little endian, false
if it is big endian.
offset
Value of the current pointer offset.
skip(n = 1)
Move the pointer forward by n
bytes.
seek(offset)
Move the pointer at the given offset.
mark()
Store the current pointer offset.
reset()
Move the pointer back to the last offset stored by mark
.
rewind()
Move the pointer back to offset 0
.
InputBuffer
new InputBuffer(data)
data
can be an ArrayBuffer or any Typed Array (including Node.js' Buffer from v4).
Methods
Each method returns the value and moves the pointer forward by the number of read bytes.
- readBoolean
- readInt8
- readUint8 / readByte / readBytes(n)
- readInt16
- readUint16
- readInt32
- readUint32
- readFloat32
- readFloat64
- readChar / readChars(n)
License
MIT