in src/utils/LoaderUtils.ts [36:63]
export async function loadChunkedDataIntoBuffer(
res: Response,
onProgress?: (progress: number) => void,
): Promise<Uint8Array> {
const reader = res.body!.getReader();
const chunks = [];
let receivedLength = 0;
// eslint-disable-next-line no-constant-condition
while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
receivedLength += value.length;
}
const buffer = new Uint8Array(receivedLength);
let position = 0;
for (const chunk of chunks) {
buffer.set(chunk, position);
position += chunk.length;
onProgress?.(position / receivedLength);
}
return buffer;
}