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";
33
44export class StreamUtils {
55 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+ } ) ;
912 }
1013
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 ) ;
1516 }
1617
17- static fromArrayBuffer ( buffer : ArrayBuffer ) : NodeJS . ReadableStream {
18- return StreamUtils . fromBuffer ( Buffer . from ( buffer ) ) ;
18+ static empty ( ) : NodeJS . ReadableStream {
19+ return Readable . from ( [ ] ) ;
1920 }
2021
2122 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 ) ;
2624 }
2725
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 ) ) ;
3028 }
3129}
You can’t perform that action at this time.
0 commit comments