@loaders.gl/core
Version:
The core API for working with loaders.gl loaders and writers
21 lines (20 loc) • 679 B
JavaScript
// loaders.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors
const DEFAULT_CHUNK_SIZE = 1024 * 1024; // 1MB — biggest value that keeps UI responsive
/**
* Returns an iterator that breaks a big Blob into chunks and yields them one-by-one
* @param blob Blob or File object
* @param options
* @param options.chunkSize
*/
export async function* makeBlobIterator(blob, options) {
const chunkSize = options?.chunkSize || DEFAULT_CHUNK_SIZE;
let offset = 0;
while (offset < blob.size) {
const end = offset + chunkSize;
const chunk = await blob.slice(offset, end).arrayBuffer();
offset = end;
yield chunk;
}
}