export async function loadDataIntoBuffer()

in src/utils/LoaderUtils.ts [15:34]


export async function loadDataIntoBuffer(res: Response, onProgress?: (progress: number) => void): Promise<Uint8Array> {
    const reader = res.body!.getReader();

    const contentLength = parseInt(res.headers.get("content-length") as string);
    const buffer = new Uint8Array(contentLength);

    let bytesRead = 0;

    // eslint-disable-next-line no-constant-condition
    while (true) {
        const { done, value } = await reader.read();
        if (done) break;

        buffer.set(value, bytesRead);
        bytesRead += value.length;
        onProgress?.(bytesRead / contentLength);
    }

    return buffer;
}