@@ -16,7 +16,7 @@ export class ReadableWebToNodeStream extends Readable {
16
16
* https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader
17
17
*/
18
18
private reader : ReadableStreamDefaultReader < Uint8Array > ;
19
- private pendingRead : Promise < { done : boolean ; value ?: Uint8Array } > | undefined ;
19
+ private pendingRead : Promise < void > | undefined ;
20
20
21
21
/**
22
22
*
@@ -33,23 +33,27 @@ export class ReadableWebToNodeStream extends Readable {
33
33
* the implementation should begin pushing that data into the read queue
34
34
* https://nodejs.org/api/stream.html#stream_readable_read_size_1
35
35
*/
36
- public async _read ( ) : Promise < void > {
36
+ public _read ( ) : void {
37
37
// Should start pushing data into the queue
38
38
// Read data from the underlying Web-API-readable-stream
39
39
if ( this . released ) {
40
40
this . push ( null ) ; // Signal EOF
41
41
return ;
42
42
}
43
- this . pendingRead = this . reader . read ( ) ;
44
- const data = await this . pendingRead ;
45
- // clear the promise before pushing new data to the queue and allow sequential calls to _read()
46
- this . pendingRead = undefined ;
47
- if ( data . done || this . released ) {
48
- this . push ( null ) ; // Signal EOF
49
- } else if ( data . value ) {
50
- this . bytesRead += data . value . length ;
51
- this . push ( data . value ) ; // Push new data to the queue
52
- }
43
+ this . pendingRead = this . reader
44
+ . read ( )
45
+ . then ( ( data ) => {
46
+ delete this . pendingRead ;
47
+ if ( data . done || this . released ) {
48
+ this . push ( null ) ; // Signal EOF
49
+ } else {
50
+ this . bytesRead += data . value . length ;
51
+ this . push ( data . value ) ; // Push new data to the queue
52
+ }
53
+ } )
54
+ . catch ( ( err ) => {
55
+ this . destroy ( err ) ;
56
+ } ) ;
53
57
}
54
58
55
59
/**
0 commit comments