@loaders.gl/core
Version:
Framework-independent loaders for 3D graphics formats
35 lines (30 loc) • 1.07 kB
JavaScript
import assert from '../utils/assert';
export function getTransferList(object, recursive = true, transfers = []) {
if (!object) {} else if (object instanceof ArrayBuffer) {
transfers.push(object);
} else if (object.buffer && object.buffer instanceof ArrayBuffer) {
transfers.push(object.buffer);
} else if (recursive && typeof object === 'object') {
for (const key in object) {
getTransferList(object[key], recursive, transfers);
}
}
return transfers;
}
const workerURLCache = new Map();
export function getWorkerURL(workerSource) {
assert(typeof workerSource === 'string', 'worker source');
if (workerSource.startsWith('url(') && workerSource.endsWith(')')) {
return workerSource.match(/^url\((.*)\)$/)[1];
}
let workerURL = workerURLCache.get(workerSource);
if (!workerURL) {
const blob = new Blob([workerSource], {
type: 'application/javascript'
});
workerURL = URL.createObjectURL(blob);
workerURLCache.set(workerSource, workerURL);
}
return workerURL;
}
//# sourceMappingURL=worker-utils.js.map