Optional
dataViewType: DataViewTypeReturns the number of items in the ArrayBuffer (including empty slots - can't determinte otherwise), taking the byteLength & byteSize of the dataViewType into account.
Optional
dataViewType: DataViewTypeOptional
dataViewType: DataViewTypeOptional
dataViewType: DataViewTypeOptional
dataViewType: DataViewTypeOptional
dataViewType: DataViewTypeRead / peek at the current index value, without advancing the cursor
Optional
dataViewType: DataViewTypeOptional
dataViewType: DataViewType
Create an
ArrayBufferCursor
to get an iterator-like reader for an ArrayBuffer. It implements theDataView
methods under the hood.NOTE: Used internally only currently, use
loop()
to wrap as an Iterator instead.Usage:
const cursor = new ArrayBufferCursor(new ArrayBuffer(16))
OR
const cursor = new ArrayBufferCursor(new ArrayBuffer(16), 'Float')
You can use the
hasNext()
to check if there are more items, andnext()
to get the next item.while (cursor.hasNext()) { // dataViewType argument 'Float' can be omitted if passed to the constructor, // or you can override it for each read. const item = cursor.next('Float')
}
See
Initial code from "Iterating through an arrayBuffer"
Param: arrayBuffer
Param: dataViewType
is optional, as it can be passed in each next()/peek()/write() operation. If it is passed on constructor, it is used as default in all operations. If missing in both constructor and in the operation calls, it throws an error.