Class inputBuffer
inputBuffer
Defined in: inputBuffer.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Class that assists in reading byte-based datastreams.
|
Field Attributes | Field Name and Description |
---|---|
The current byte index being read.
|
|
Size of the input bufer stream in bytes.
|
Method Attributes | Method Name and Description |
---|---|
open(path)
Opens the given file as the source of an input buffer.
|
|
openBuffer(array)
Opens the given array as the source of an input buffer.
|
|
read(type)
Reads the next object from the given byte stream.
|
|
readString(numBytes)
Reads a UTF8 string object from the input buffer.
|
Class Detail
inputBuffer()
Class that assists in reading byte-based datastreams. granting
the ability to read wherever in the stream you wish. You can convert
groups of byte data into familiar types, or just retrieve the raw data itself.
When working with binary assets, it's often necessary to work with raw byte data.
Inherently, Javascript doesn't provide many ways to handle
non-text data manipulation. inputBuffer Allows for reading that sort of
data to be interpreted later, or read stream-wise. This contrasts with
outputBuffer, which aims to be the write-only complement to inputBuffer.
js // Creates a new inputbuffer from the static helper in sandboxe var myBuffer = sandboxe.inputBuffer.create(); // Opens a file named 'binaryFile' and dumps its contents within the buffer. myBuffer.open('binaryFile'); // Reads a floating point (decimal) value from the buffer value1 = myBuffer.read(sandboxe.type.float); // Then reads the next 10 bytes as a UTF8 string. str1 = myBuffer.readString(13);
Field Detail
position
The current byte index being read. The position is automatically updated
when reading using inputBuffer.read and similar functions
size
Size of the input bufer stream in bytes. Writing this property does nothing.
Method Detail
open(path)
Opens the given file as the source of an input buffer.
- Parameters:
- {String} path
- Path to the file to open as an input buffer.
openBuffer(array)
Opens the given array as the source of an input buffer. The data is copied and
placed within the input buffer, so the input array does not need to be preserved.
- Parameters:
- {Array} array
- An array of raw byte values.
{Object}
read(type)
Reads the next object from the given byte stream.
- Parameters:
- {Number} type
- Refer to sandboxe.type for valid values to be read.
- Returns:
- {Object} The value requested.
readString(numBytes)
Reads a UTF8 string object from the input buffer.
- Parameters:
- {Number} numBytes
- The number of characters to read from the buffer.