From 7f7ff86f9f47db7a80cdc86d107e50e951281288 Mon Sep 17 00:00:00 2001 From: Yeicor <4929005+Yeicor@users.noreply.github.com> Date: Fri, 16 Feb 2024 21:49:01 +0100 Subject: [PATCH] starting work on glb(s) management 2 --- src/models/glb/glbs.ts | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/models/glb/glbs.ts b/src/models/glb/glbs.ts index e46bc50..8d9c255 100644 --- a/src/models/glb/glbs.ts +++ b/src/models/glb/glbs.ts @@ -51,28 +51,24 @@ async function singleBlob(reader: ReadableStream, stopAfter: number // Make sure the reader reads the entire stream at once. const readerImpl = reader.getReader(); let bufferedChunks: Uint8Array = new Uint8Array(); - try { - let done = false; - let length = 0; - while (!done) { - let {value, done: d} = await readerImpl.read(); - if (value) { - // TODO: This is inefficient. We should be able to avoid copying the buffer each time. byob? - let oldBuffer = bufferedChunks; - let newLength = bufferedChunks.length + value.length; - if (stopAfter !== null && newLength > stopAfter) { - newLength = stopAfter; - value = value.slice(0, stopAfter - bufferedChunks.length); - } - bufferedChunks = new Uint8Array(newLength); - bufferedChunks.set(oldBuffer); - bufferedChunks.set(value, length); - length += value.length; + let done = false; + let length = 0; + while (!done) { + let {value, done: d} = await readerImpl.read(); + if (value) { + // TODO: This is inefficient. We should be able to avoid copying the buffer each time. byob? + let oldBuffer = bufferedChunks; + let newLength = bufferedChunks.length + value.length; + if (stopAfter !== null && newLength > stopAfter) { + newLength = stopAfter; + value = value.slice(0, stopAfter - bufferedChunks.length); } - done = d; + bufferedChunks = new Uint8Array(newLength); + bufferedChunks.set(oldBuffer); + bufferedChunks.set(value, length); + length += value.length; } - } finally { - await readerImpl.cancel(); + done = d; } return new ReadableStream({ start(controller) {