There was an error while loading. Please reload this page.
1 parent ee6e6fb commit 7eaed6aCopy full SHA for 7eaed6a
1 file changed
src/sparse.js
@@ -43,11 +43,16 @@ export async function from(stream) {
43
let buffer = new Uint8Array(0);
44
45
const readUntil = async (byteLength) => {
46
- while (buffer.byteLength < byteLength) {
+ if (buffer.byteLength >= byteLength) return;
47
+ const parts = [buffer];
48
+ let size = buffer.byteLength;
49
+ while (size < byteLength) {
50
const { value, done } = await reader.read();
51
if (done) throw new Error("Unexpected end of stream");
- buffer = concatUint8Array([buffer, value]);
52
+ parts.push(value);
53
+ size += value.byteLength;
54
}
55
+ buffer = concatUint8Array(parts);
56
57
58
let header;
0 commit comments