Skip to content

Commit 682f527

Browse files
Merge branch 'master' into jlarabie/money-exchange
2 parents 93ea98f + 1b0ac07 commit 682f527

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

crates/bindings-typescript/src/sdk/decompress.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,24 @@ export async function decompress(
2828
const decompressedStream = readableStream.pipeThrough(decompressionStream);
2929

3030
// Collect the decompressed chunks efficiently
31-
const chunks = [];
32-
for await (const chunk of decompressedStream) {
33-
chunks.push(chunk);
31+
const reader = decompressedStream.getReader();
32+
const chunks: Uint8Array[] = [];
33+
let totalLength = 0;
34+
let result: any;
35+
36+
while (!(result = await reader.read()).done) {
37+
chunks.push(result.value);
38+
totalLength += result.value.length;
3439
}
35-
return new Blob(chunks).bytes();
40+
41+
// Allocate a single Uint8Array for the decompressed data
42+
const decompressedArray = new Uint8Array(totalLength);
43+
let chunkOffset = 0;
44+
45+
for (const chunk of chunks) {
46+
decompressedArray.set(chunk, chunkOffset);
47+
chunkOffset += chunk.length;
48+
}
49+
50+
return decompressedArray;
3651
}

0 commit comments

Comments
 (0)