IOBuffer
Class for writing and reading binary data
Constructor Summary
Public Constructor | ||
public |
constructor(data: undefined | number | ArrayBuffer | TypedArray | IOBuffer | Buffer, params: object) |
Member Summary
Public Members | ||
public |
Reference to the internal ArrayBuffer object |
|
public |
Byte length of the internal ArrayBuffer |
|
public |
Byte offset of the internal ArrayBuffer |
|
public |
Byte length of the internal ArrayBuffer |
|
public |
|
|
public |
The current offset of the buffer's pointer |
Private Members | ||
private |
|
|
private |
|
|
private |
|
|
private |
|
Method Summary
Public Methods | ||
public |
Checks if the memory allocated to the buffer is sufficient to store more bytes after the offset |
|
public |
ensureAvailable(byteLength: number): IOBuffer 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) |
|
public |
getBuffer(): Buffer | Uint8Array Same as IOBuffer#toArray but returns a Buffer if possible. |
|
public |
Check if big-endian mode is used for reading and writing multi-byte values |
|
public |
Check if little-endian mode is used for reading and writing multi-byte values |
|
public |
Store the current pointer offset. |
|
public |
Pop the last pointer offset from the mark stack, and set the current pointer offset to the popped value |
|
public |
Push the current pointer offset to the mark stack |
|
public |
Read a byte and return false if the byte's value is 0, or true otherwise Moves pointer forward |
|
public |
Alias for IOBuffer#readUint8 |
|
public |
readBytes(n: number): Uint8Array Read n bytes and move pointer forward. |
|
public |
Read 1-byte ascii character and move pointer forward |
|
public |
Read n 1-byte ascii characters and move pointer forward |
|
public |
Read a 32-bit floating number and move pointer forward |
|
public |
Read a 64-bit floating number and move pointer forward |
|
public |
Read a 16-bit signed integer and move pointer forward |
|
public |
Read a 32-bit signed integer and move pointer forward |
|
public |
Read a signed 8-bit integer and move pointer forward |
|
public |
readUint16(): number Read a 16-bit unsigned integer and move pointer forward |
|
public |
readUint32(): number Read a 32-bit unsigned integer and move pointer forward |
|
public |
Read an unsigned 8-bit integer and move pointer forward |
|
public |
Move the pointer back to the last pointer offset set by mark |
|
public |
Move the pointer offset back to 0 |
|
public |
Move the pointer to the given offset |
|
public |
Switches to big-endian mode for reading and writing multi-byte values |
|
public |
Set little-endian mode for reading and writing multi-byte values |
|
public |
Move the pointer n bytes forward |
|
public |
Export a Uint8Array view of the internal buffer. |
|
public |
writeBoolean(value: any): IOBuffer Write 0xff if the passed value is truthy, 0x00 otherwise |
|
public |
An alias for IOBuffer#writeUint8 |
|
public |
writeBytes(bytes: Array | Uint8Array): IOBuffer Write bytes |
|
public |
Write the charCode of the passed string's first character to the current pointer offset |
|
public |
writeChars(str: string): IOBuffer Write the charCodes of the passed string's characters to the current pointer offset |
|
public |
writeFloat32(value: number): IOBuffer Write a 32-bit floating number at the current pointer offset |
|
public |
writeFloat64(value: number): IOBuffer Write a 64-bit floating number at the current pointer offset |
|
public |
writeInt16(value: number): IOBuffer Write value as an 16-bit signed integer |
|
public |
writeInt32(value: number): IOBuffer Write a 32-bit signed integer at the current pointer offset |
|
public |
Write value as an 8-bit signed integer |
|
public |
writeUint16(value: number): IOBuffer Write value as a 16-bit unsigned integer |
|
public |
writeUint32(value: number): IOBuffer Write a 32-bit unsigned integer at the current pointer offset |
|
public |
writeUint8(value: number): IOBuffer Write value as a 8-bit unsigned integer |
Private Methods | ||
private |
Update the last written byte offset |
Public Constructors
public constructor(data: undefined | number | ArrayBuffer | TypedArray | IOBuffer | Buffer, params: object) source
Params:
Name | Type | Attribute | Description |
data | undefined | number | ArrayBuffer | TypedArray | IOBuffer | Buffer | The data to construct the IOBuffer with. If it's a number, it will initialize the buffer with the number as the buffer's length. If it's undefined, it will initialize the buffer with a default length of 8 Kb. If its an ArrayBuffer, a TypedArray, an IOBuffer instance, or a Node.js Buffer, it will create a view over the underlying ArrayBuffer. |
|
params | object |
|
|
params.offset | number |
|
Ignore the first n bytes of the ArrayBuffer |
Public Members
public littleEndian source
Private Members
private _data source
private _lastWrittenByte source
private _mark source
private _marks source
Public Methods
public available(byteLength: number): boolean source
Checks if the memory allocated to the buffer is sufficient to store more bytes after the offset
Params:
Name | Type | Attribute | Description |
byteLength | number |
|
The needed memory in bytes |
public ensureAvailable(byteLength: number): IOBuffer source
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)
Params:
Name | Type | Attribute | Description |
byteLength | number |
|
public getBuffer(): Buffer | Uint8Array source
Same as IOBuffer#toArray but returns a Buffer if possible. Otherwise returns a Uint8Array.
public isBigEndian(): boolean source
Check if big-endian mode is used for reading and writing multi-byte values
public isLittleEndian(): boolean source
Check if little-endian mode is used for reading and writing multi-byte values
public popMark(): IOBuffer source
Pop the last pointer offset from the mark stack, and set the current pointer offset to the popped value
public readBoolean(): boolean source
Read a byte and return false if the byte's value is 0, or true otherwise Moves pointer forward
public readBytes(n: number): Uint8Array source
Read n bytes and move pointer forward.
Params:
Name | Type | Attribute | Description |
n | number |
public readChars(n: number): string source
Read n 1-byte ascii characters and move pointer forward
Params:
Name | Type | Attribute | Description |
n | number |
public seek(offset: number): IOBuffer source
Move the pointer to the given offset
Params:
Name | Type | Attribute | Description |
offset | number |
public setBigEndian(): IOBuffer source
Switches to big-endian mode for reading and writing multi-byte values
public setLittleEndian(): IOBuffer source
Set little-endian mode for reading and writing multi-byte values
public skip(n: number): IOBuffer source
Move the pointer n bytes forward
Params:
Name | Type | Attribute | Description |
n | number |
public toArray(): Uint8Array source
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.
public writeBoolean(value: any): IOBuffer source
Write 0xff if the passed value is truthy, 0x00 otherwise
Params:
Name | Type | Attribute | Description |
value | any |
public writeByte(value: number): IOBuffer source
An alias for IOBuffer#writeUint8
Params:
Name | Type | Attribute | Description |
value | number |
public writeBytes(bytes: Array | Uint8Array): IOBuffer source
Write bytes
Params:
Name | Type | Attribute | Description |
bytes | Array | Uint8Array |
public writeChar(str: string): IOBuffer source
Write the charCode of the passed string's first character to the current pointer offset
Params:
Name | Type | Attribute | Description |
str | string | The character to set |
public writeChars(str: string): IOBuffer source
Write the charCodes of the passed string's characters to the current pointer offset
Params:
Name | Type | Attribute | Description |
str | string |
public writeFloat32(value: number): IOBuffer source
Write a 32-bit floating number at the current pointer offset
Params:
Name | Type | Attribute | Description |
value | number | The value to set |
public writeFloat64(value: number): IOBuffer source
Write a 64-bit floating number at the current pointer offset
Params:
Name | Type | Attribute | Description |
value | number |
public writeInt16(value: number): IOBuffer source
Write value as an 16-bit signed integer
Params:
Name | Type | Attribute | Description |
value | number |
public writeInt32(value: number): IOBuffer source
Write a 32-bit signed integer at the current pointer offset
Params:
Name | Type | Attribute | Description |
value | number |
public writeInt8(value: number): IOBuffer source
Write value as an 8-bit signed integer
Params:
Name | Type | Attribute | Description |
value | number |
public writeUint16(value: number): IOBuffer source
Write value as a 16-bit unsigned integer
Params:
Name | Type | Attribute | Description |
value | number |
public writeUint32(value: number): IOBuffer source
Write a 32-bit unsigned integer at the current pointer offset
Params:
Name | Type | Attribute | Description |
value | number | The value to set |
public writeUint8(value: number): IOBuffer source
Write value as a 8-bit unsigned integer
Params:
Name | Type | Attribute | Description |
value | number |