6
6
// Helper function that triggers garbage collection while reading a chunk
7
7
// if perform_gc is true.
8
8
async function read_and_gc ( reader , perform_gc ) {
9
- const read_promise = reader . read ( ) ;
9
+ // Passing Uint8Array for byte streams; non-byte streams will simply ignore it
10
+ const read_promise = reader . read ( new Uint8Array ( 64 ) ) ;
10
11
if ( perform_gc ) {
11
12
await garbageCollect ( ) ;
12
13
}
@@ -16,10 +17,10 @@ async function read_and_gc(reader, perform_gc) {
16
17
// Takes in a ReadableStream and reads from it until it is done, returning
17
18
// an array that contains the results of each read operation. If perform_gc
18
19
// is true, garbage collection is triggered while reading every chunk.
19
- async function read_all_chunks ( stream , perform_gc = false ) {
20
+ async function read_all_chunks ( stream , { perform_gc = false , mode } = { } ) {
20
21
assert_true ( stream instanceof ReadableStream ) ;
21
22
assert_true ( 'getReader' in stream ) ;
22
- const reader = stream . getReader ( ) ;
23
+ const reader = stream . getReader ( { mode } ) ;
23
24
24
25
assert_true ( 'read' in reader ) ;
25
26
let read_value = await read_and_gc ( reader , perform_gc ) ;
@@ -67,7 +68,16 @@ promise_test(async() => {
67
68
const stream = blob . stream ( ) ;
68
69
blob = null ;
69
70
await garbageCollect ( ) ;
70
- const chunks = await read_all_chunks ( stream , /* perform_gc=*/ true ) ;
71
+ const chunks = await read_all_chunks ( stream , { perform_gc : true } ) ;
71
72
assert_array_equals ( chunks , input_arr ) ;
72
73
} , "Blob.stream() garbage collection of blob shouldn't break stream" +
73
74
"consumption" )
75
+
76
+ promise_test ( async ( ) => {
77
+ const input_arr = [ 8 , 241 , 48 , 123 , 151 ] ;
78
+ const typed_arr = new Uint8Array ( input_arr ) ;
79
+ let blob = new Blob ( [ typed_arr ] ) ;
80
+ const stream = blob . stream ( ) ;
81
+ const chunks = await read_all_chunks ( stream , { mode : "byob" } ) ;
82
+ assert_array_equals ( chunks , input_arr ) ;
83
+ } , "Reading Blob.stream() with BYOB reader" )
0 commit comments