ArrayBuffer
Functions for interacting with JavaScript ArrayBuffer.
See: ArrayBuffer.
t
RESCRIPT
type tType representing an ArrayBuffer object used to represent a generic raw binary data buffer.
make
RESCRIPT
let make: int => tmake(length) creates a new ArrayBuffer with the specified length in bytes.
See ArrayBuffer on MDN.
Examples
RESCRIPTlet buffer = ArrayBuffer.make(8)
ArrayBuffer.byteLength(buffer) == 8
Exceptions
RangeError: Iflengthis larger thanNumber.MAX_SAFE_INTEGERor negative.
byteLength
RESCRIPT
let byteLength: t => intbyteLength(arrayBuffer) returns the size, in bytes, of the ArrayBuffer.
See ArrayBuffer.byteLength on MDN.
Examples
RESCRIPTlet buffer = ArrayBuffer.make(16)
ArrayBuffer.byteLength(buffer) == 16
slice
RESCRIPT
let slice: (t, ~start: int=?, ~end: int=?) => tslice(arrayBuffer, ~start, ~end) returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer's bytes from start, inclusive, up to end, exclusive.
See ArrayBuffer.slice on MDN.
Examples
RESCRIPTlet buffer = ArrayBuffer.make(16)
let sliced = buffer->ArrayBuffer.slice(~start=4, ~end=12)
ArrayBuffer.byteLength(sliced) == 8
sliceToEnd
Deprecated
RESCRIPT
let sliceToEnd: (t, ~start: int) => t