File tree Expand file tree Collapse file tree 1 file changed +13
-15
lines changed Expand file tree Collapse file tree 1 file changed +13
-15
lines changed Original file line number Diff line number Diff line change @@ -3,29 +3,27 @@ import type * as stream from "stream";
3
3
4
4
export class StreamUtils {
5
5
static create ( ) : stream . Readable {
6
- const readable = new Readable ( ) ;
7
- readable . _read = ( ) => { } ; // _read is required but you can noop it
8
- return readable ;
6
+ return new Readable ( {
7
+ read ( _size ) {
8
+ // No implementation needed here.
9
+ // The stream will wait for data to be pushed externally.
10
+ }
11
+ } ) ;
9
12
}
10
13
11
- static empty ( ) : NodeJS . ReadableStream {
12
- const readable = StreamUtils . create ( ) ;
13
- StreamUtils . endStream ( readable ) ;
14
- return readable ;
14
+ static endStream ( readable : stream . Readable ) : void {
15
+ readable . push ( null ) ;
15
16
}
16
17
17
- static fromArrayBuffer ( buffer : ArrayBuffer ) : NodeJS . ReadableStream {
18
- return StreamUtils . fromBuffer ( Buffer . from ( buffer ) ) ;
18
+ static empty ( ) : NodeJS . ReadableStream {
19
+ return Readable . from ( [ ] ) ;
19
20
}
20
21
21
22
static fromBuffer ( buffer : Buffer ) : NodeJS . ReadableStream {
22
- const readable = StreamUtils . create ( ) ;
23
- readable . push ( buffer ) ;
24
- StreamUtils . endStream ( readable ) ;
25
- return readable ;
23
+ return Readable . from ( buffer ) ;
26
24
}
27
25
28
- static endStream ( readable : stream . Readable ) : void {
29
- readable . push ( null ) ;
26
+ static fromArrayBuffer ( buffer : ArrayBuffer ) : NodeJS . ReadableStream {
27
+ return StreamUtils . fromBuffer ( Buffer . from ( buffer ) ) ;
30
28
}
31
29
}
You can’t perform that action at this time.
0 commit comments