ArrayBuffer

Functions for interacting with JavaScript ArrayBuffer. See: ArrayBuffer.

byteLength

RESCRIPT
let byteLength: t => int

byteLength(arrayBuffer) returns the size, in bytes, of the ArrayBuffer. See ArrayBuffer.byteLength on MDN.

Examples

RESCRIPT
let buffer = ArrayBuffer.make(16) ArrayBuffer.byteLength(buffer) == 16

make

RESCRIPT
let make: int => t

make(length) creates a new ArrayBuffer with the specified length in bytes. See ArrayBuffer on MDN.

Examples

RESCRIPT
let buffer = ArrayBuffer.make(8) ArrayBuffer.byteLength(buffer) == 8

Exceptions

  • RangeError: If length is larger than Number.MAX_SAFE_INTEGER or negative.

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

RESCRIPT
let 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

t

RESCRIPT
type t

Type representing an ArrayBuffer object used to represent a generic raw binary data buffer.