@loaders.gl/core
Version:
Framework-independent loaders for 3D graphics formats
21 lines (17 loc) • 538 B
JavaScript
import assert from '../../utils/assert';
// Convert (copy) ArrayBuffer to Buffer
export default function toBuffer(binaryData) {
if (ArrayBuffer.isView(binaryData)) {
binaryData = binaryData.buffer;
}
if (typeof Buffer !== 'undefined' && binaryData instanceof ArrayBuffer) {
/* global Buffer */
const buffer = new Buffer(binaryData.byteLength);
const view = new Uint8Array(binaryData);
for (let i = 0; i < buffer.length; ++i) {
buffer[i] = view[i];
}
return buffer;
}
return assert(false);
}