@@ -329,34 +329,38 @@ class Blob {
329
329
pull ( c ) {
330
330
const { promise, resolve, reject } = createDeferredPromise ( ) ;
331
331
this . pendingPulls . push ( { resolve, reject } ) ;
332
- reader . pull ( ( status , buffer ) => {
333
- // If pendingPulls is empty here, the stream had to have
334
- // been canceled, and we don't really care about the result.
335
- // we can simply exit.
336
- if ( this . pendingPulls . length === 0 ) {
337
- return ;
338
- }
339
- const pending = this . pendingPulls . shift ( ) ;
340
- if ( status === 0 ) {
341
- // EOS
342
- c . close ( ) ;
343
- pending . resolve ( ) ;
344
- return ;
345
- } else if ( status < 0 ) {
346
- // The read could fail for many different reasons when reading
347
- // from a non-memory resident blob part (e.g. file-backed blob).
348
- // The error details the system error code.
349
- const error = lazyDOMException ( 'The blob could not be read' , 'NotReadableError' ) ;
350
-
351
- c . error ( error ) ;
352
- pending . reject ( error ) ;
353
- return ;
354
- }
355
- if ( buffer !== undefined ) {
356
- c . enqueue ( new Uint8Array ( buffer ) ) ;
357
- }
358
- pending . resolve ( ) ;
359
- } ) ;
332
+ const readNext = ( ) => {
333
+ reader . pull ( ( status , buffer ) => {
334
+ // If pendingPulls is empty here, the stream had to have
335
+ // been canceled, and we don't really care about the result.
336
+ // We can simply exit.
337
+ if ( this . pendingPulls . length === 0 ) {
338
+ return ;
339
+ }
340
+ if ( status === 0 ) {
341
+ // EOS
342
+ c . close ( ) ;
343
+ const pending = this . pendingPulls . shift ( ) ;
344
+ pending . resolve ( ) ;
345
+ return ;
346
+ } else if ( status < 0 ) {
347
+ // The read could fail for many different reasons when reading
348
+ // from a non-memory resident blob part (e.g. file-backed blob).
349
+ // The error details the system error code.
350
+ const error = lazyDOMException ( 'The blob could not be read' , 'NotReadableError' ) ;
351
+ const pending = this . pendingPulls . shift ( ) ;
352
+ c . error ( error ) ;
353
+ pending . reject ( error ) ;
354
+ return ;
355
+ }
356
+ if ( buffer !== undefined ) {
357
+ c . enqueue ( new Uint8Array ( buffer ) ) ;
358
+ }
359
+ // We keep reading until we either reach EOS or some error
360
+ queueMicrotask ( ( ) => readNext ( ) ) ;
361
+ } ) ;
362
+ } ;
363
+ readNext ( ) ;
360
364
return promise ;
361
365
} ,
362
366
cancel ( reason ) {
0 commit comments