File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
packages/stream-collector-browser/src Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { StreamCollector } from "@aws-sdk/types" ;
2
2
3
- export const streamCollector : StreamCollector = (
4
- stream : ReadableStream
3
+ export const streamCollector : StreamCollector = async (
4
+ stream : ReadableStream < Uint8Array >
5
5
) : Promise < Uint8Array > => {
6
- return new Response ( stream )
7
- . arrayBuffer ( )
8
- . then ( arrayBuffer => new Uint8Array ( arrayBuffer ) ) ;
6
+ let res = new Uint8Array ( 0 ) ;
7
+ const reader = stream . getReader ( ) ;
8
+ let isDone = false ;
9
+ while ( ! isDone ) {
10
+ const { done, value } = await reader . read ( ) ;
11
+ if ( value ) {
12
+ const prior = res ;
13
+ res = new Uint8Array ( prior . length + value . length ) ;
14
+ res . set ( prior ) ;
15
+ res . set ( value , prior . length ) ;
16
+ }
17
+ isDone = done ;
18
+ }
19
+ return res ;
9
20
} ;
You can’t perform that action at this time.
0 commit comments