The loaders.gl API consistently uses
ArrayBuffers to represent and transport binary data.
One of the design goals of loaders.gl is to provide applications with a single, consistent API that works across (reasonably modern) browsers, worker threads and Node.js. One of the characteristics of this API is how binary data is represented.
loaders.gl "standardizes" on ArrayBuffers for a number of reasons:
Bufferclass is now backed by an
Recall that typed arrays (e.g.
Float32Array) are just views into array buffers. Every typed array has a
Many loaders.gl functions directly accept typed arrays, which essentially means they accept the associated ArrayBuffer. However, be aware that typed arrays can represent partial views (i.e. they can have offsets) that sometimes need special handling in the application.
We use the
Since these classes are central to using ArrayBuffers correctly, loaders.gl provides polyfills for them under Node.js.
Binary data types in JS:
Uint8Arrayand other typed arrays, plus
Examples of "semi-binary" data types in JS:
Array: Array of bytes (elements are numbers between 0 and 255).
String(binary): string in “binary” form, 1 byte per char (2 bytes).
String(base64): string containing the binary data encoded in a base64 form.