File tree Expand file tree Collapse file tree
crates/bindings-typescript/src/sdk Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments