Skip to content

Commit 1b0ac07

Browse files
authored
Don't use ReadableStream as an asyncIterator (#5144)
# Description of Changes Reverts part of #4561. Fixes an issue with `ReadableStream[Symbol.asyncIterator]` not being defined on safari until recently. # Expected complexity level and risk 1 # Testing - [x] Chrome <!-- Confirmed by @coolreader18 --> - [x] Firefox <!-- Confirmed by @coolreader18 --> - [x] Safari <!-- Confirmed by @joshua-spacetime --> (Run a web template project in safari with `.withCompression('gzip')`)
1 parent b6b072e commit 1b0ac07

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)