@jbrowse/core
Version:
JBrowse 2 core libraries used by plugins
36 lines (35 loc) • 1.13 kB
JavaScript
export function isDetachedBuffer(buffer) {
return buffer.byteLength === 0;
}
function isImageBitmap(value) {
return typeof ImageBitmap !== 'undefined' && value instanceof ImageBitmap;
}
function isArrayBufferLike(value) {
return (value !== null &&
typeof value === 'object' &&
typeof value.byteLength === 'number');
}
export function collectTransferables(result) {
const transferables = [];
const { imageData, flatbush, subfeatureFlatbush } = result;
if (isImageBitmap(imageData)) {
transferables.push(imageData);
}
if (isArrayBufferLike(flatbush)) {
if (isDetachedBuffer(flatbush)) {
console.warn('flatbush buffer is already detached, cannot transfer');
}
else {
transferables.push(flatbush);
}
}
if (isArrayBufferLike(subfeatureFlatbush)) {
if (isDetachedBuffer(subfeatureFlatbush)) {
console.warn('subfeatureFlatbush buffer is already detached, cannot transfer');
}
else {
transferables.push(subfeatureFlatbush);
}
}
return transferables;
}