Core API / binary data
Make binary inputs predictable before decoding.
Browser and Node.js APIs represent bytes in several compatible but non-identical forms. The core binary utilities normalize those inputs so loaders and application code can share one boundary.
Binary input boundary
Normalize once, then let the format parser work.
The utility functions handle the common differences between ArrayBuffer, typed arrays, Node.js Buffer, Blob, and related values. This keeps format-specific code focused on decoding rather than transport representation.
Accept
ArrayBuffer, Buffer, typed arrays, Blob, and related binary values.
Normalize
Convert compatible input into an ArrayBuffer representation.
Decode
Pass stable bytes to loaders, parsers, and format utilities.
Share
Use the same helper across browser and Node.js paths.
Detailed guide
Binary utility reference
The detailed reference lists normalization functions, accepted inputs, view boundaries, and the cases where a copy may be required.
loaders.gl provides a set of functions to simplify working with binary data. There are a couple of different ways to deal with binary data in the JavaScript APIs for browser and Node.js, and some small but annoying "gotchas" that can trip up programmers when working with binary data.
Usage
import {toArrayBuffer} from '@loaders.gl/core/loader-utils';
Functions
toArrayBuffer(binaryData : *) : ArrayBuffer
Converts an ArrayBuffer, shared array buffer, typed-array view, Node.js buffer,
or string to an ArrayBuffer. Strings are encoded as UTF-8. Full-buffer views can
reuse their backing buffer; partial views are sliced to their byte range, and
shared buffers are copied.
Native Blob values require asynchronous reading with await blob.arrayBuffer();
this synchronous helper does not read them.