The data to construct the IOBuffer with.
If data is a number, it will be the new buffer's length
If data is undefined
, the buffer will be initialized with a default length of 8Kb
If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,
or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.
An object for the options.
A new IOBuffer instance.
Reference to the internal ArrayBuffer object.
Byte length of the internal ArrayBuffer.
Byte offset of the internal ArrayBuffer.
Byte length of the internal ArrayBuffer.
The current offset of the buffer's pointer.
Checks if the memory allocated to the buffer is sufficient to store more bytes after the offset.
The needed memory in bytes.
true
if there is sufficient space and false
otherwise.
Move the pointer n bytes backward.
Number of bytes to move back.
This.
Read the next n
bytes, return a string decoded with encoding
and move pointer
forward by n
bytes.
If no encoding is passed, the function is equivalent to
Number of bytes to read.
The encoding to use. Default is 'utf8'.
The decoded string.
Make sure the buffer has sufficient memory to write a given byteLength at the current pointer offset. If the buffer's memory is insufficient, this method will create a new buffer (a copy) with a length that is twice (byteLength + current offset).
The needed memory in bytes.
This.
Get the total number of bytes written so far, regardless of the current offset.
Check if big-endian mode is used for reading and writing multi-byte values.
true
if big-endian mode is used, false
otherwise.
Check if little-endian mode is used for reading and writing multi-byte values.
true
if little-endian mode is used, false
otherwise.
Pop the last pointer offset from the mark stack, and set the current pointer offset to the popped value.
This.
Creates an array of corresponding to the type type
and size size
.
For example type uint8
will create a Uint8Array
.
size of the resulting array
number type of elements to read
The read array.
Read a 64-bit signed integer number and move pointer forward by 8 bytes.
The read value.
Read a 64-bit unsigned integer number and move pointer forward by 8 bytes.
The read value.
Read a byte and return false if the byte's value is 0, or true otherwise. Moves pointer forward by one byte.
The read boolean.
Read n
bytes and move pointer forward by n
bytes.
Number of bytes to read.
The read bytes.
Read a 1-byte ASCII character and move pointer forward by 1 byte.
The read character.
Read n
1-byte ASCII characters and move pointer forward by n
bytes.
Number of characters to read.
The read characters.
Read a 32-bit floating number and move pointer forward by 4 bytes.
The read value.
Read a 64-bit floating number and move pointer forward by 8 bytes.
The read value.
Read a 16-bit signed integer and move pointer forward by 2 bytes.
The read value.
Read a 32-bit signed integer and move pointer forward by 4 bytes.
The read value.
Read a signed 8-bit integer and move pointer forward by 1 byte.
The read byte.
Read a 16-bit unsigned integer and move pointer forward by 2 bytes.
The read value.
Read a 32-bit unsigned integer and move pointer forward by 4 bytes.
The read value.
Read an unsigned 8-bit integer and move pointer forward by 1 byte.
The read byte.
Read the next n
bytes, return a UTF-8 decoded string and move pointer
forward by n
bytes.
Number of bytes to read.
The decoded string.
Move the pointer offset back to 0.
This.
Move the pointer to the given offset.
The offset to move to.
This.
Switches to big-endian mode for reading and writing multi-byte values.
This.
Set little-endian mode for reading and writing multi-byte values.
This.
Move the pointer n bytes forward.
Number of bytes to skip.
This.
Export a Uint8Array view of the internal buffer. The view starts at the byte offset and its length is calculated to stop at the last written byte or the original length.
A new Uint8Array view.
Write value
as a 64-bit signed bigint and move pointer forward by 8
bytes.
The value to write.
This.
Write value
as a 64-bit unsigned bigint and move pointer forward by 8
bytes.
The value to write.
This.
Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer forward by 1 byte.
The value to write.
This.
Write all elements of bytes
as uint8 values and move pointer forward by
bytes.length
bytes.
The array of bytes to write.
This.
Write the charCode of str
's first character as an 8-bit unsigned integer
and move pointer forward by 1 byte.
The character to write.
This.
Write the charCodes of all str
's characters as 8-bit unsigned integers
and move pointer forward by str.length
bytes.
The characters to write.
This.
Write value
as a 32-bit floating number and move pointer forward by 4
bytes.
The value to write.
This.
Write value
as a 64-bit floating number and move pointer forward by 8
bytes.
The value to write.
This.
Write value
as a 16-bit signed integer and move pointer forward by 2
bytes.
The value to write.
This.
Write value
as a 32-bit signed integer and move pointer forward by 4
bytes.
The value to write.
This.
Write value
as an 8-bit signed integer and move pointer forward by 1 byte.
The value to write.
This.
Write value
as a 16-bit unsigned integer and move pointer forward by 2
bytes.
The value to write.
This.
Write value
as a 32-bit unsigned integer and move pointer forward by 4
bytes.
The value to write.
This.
Write value
as an 8-bit unsigned integer and move pointer forward by 1
byte.
The value to write.
This.
UTF-8 encode and write str
to the current pointer offset and move pointer
forward according to the encoded length.
The string to write.
This.
Create a new IOBuffer.