Class ArrayBufferCursor

Create an ArrayBufferCursor to get an iterator-like reader for an ArrayBuffer. It implements the DataView 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, and next() 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')

 // process item

 // write back to array at current cursor position
 cursor.write(item)
 cursor.write(item, 'Float') // override the dataViewType

 // or use cursor.dataView to write directly
 cursor.dataView.setFloat32(cursor.index, item)

}

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.

Constructors

Methods

  • Returns the number of items in the ArrayBuffer (including empty slots - can't determinte otherwise), taking the byteLength & byteSize of the dataViewType into account.

    Parameters

    Returns number

Properties

dataview: DataView
arrayBuffer: ArrayBuffer
dataViewType?: DataViewType