Optimize data concatenation in EJS_Download by using Blob to reduce iterations

This commit is contained in:
Michael Green 2026-01-17 18:01:44 +11:00
parent 3d824853af
commit 8cf9114b9d

View File

@ -133,12 +133,10 @@ class EJS_Download {
onProgress("downloading", Math.floor(received / contentLength * 100), received, contentLength);
}
}
data = new Uint8Array(chunks.reduce((acc, val) => acc + val.length, 0));
let offset = 0;
for (const chunk of chunks) {
data.set(chunk, offset);
offset += chunk.length;
}
// Optimize concatenation by leveraging Blob to avoid double iteration
const blob = new Blob(chunks);
const ab = await blob.arrayBuffer();
data = new Uint8Array(ab);
} else {
data = await resp[responseType]();
}