OptionaldataViewType: DataViewTypeReturns the number of items in the ArrayBuffer (including empty slots - can't determinte otherwise), taking the byteLength & byteSize of the dataViewType into account.
OptionaldataViewType: DataViewTypeOptionaldataViewType: DataViewTypeOptionaldataViewType: DataViewTypeOptionaldataViewType: DataViewTypeOptionaldataViewType: DataViewTypeRead / peek at the current index value, without advancing the cursor
OptionaldataViewType: DataViewTypeOptionaldataViewType: DataViewType
Create an
ArrayBufferCursorto get an iterator-like reader for an ArrayBuffer. It implements theDataViewmethods 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.