ArrayBuffer
Functions for interacting with JavaScript ArrayBuffer.
See: ArrayBuffer
.
t
RESCRIPT
type t
Type representing an ArrayBuffer object used to represent a generic raw binary data buffer.
make
RESCRIPT
let make: int => t
make(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
: Iflength
is larger thanNumber.MAX_SAFE_INTEGER
or negative.
byteLength
RESCRIPT
let byteLength: t => int
byteLength(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=?) => t
slice(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