File tree Expand file tree Collapse file tree 2 files changed +30
-7
lines changed Expand file tree Collapse file tree 2 files changed +30
-7
lines changed Original file line number Diff line number Diff line change 22
33const { Readable } = require ( 'stream' ) ;
44
5- let c = 'a' . charCodeAt ( 0 ) ;
6-
75class MyReadable extends Readable {
86 constructor ( ) {
97 super ( ) ;
108 }
119
1210 _read ( ) {
13- this . push ( String . fromCharCode ( c ++ ) ) ;
14- if ( c > 'z' . charCodeAt ( 0 ) ) {
15- this . push ( null ) ;
16- }
11+ this . push ( String . fromCharCode ( this . #c++ ) ) ;
12+ if ( this . #c> 'z' . charCodeAt ( 0 ) ) this . push ( null ) ;
1713 }
14+
15+ #c = 'a' . charCodeAt ( 0 ) ;
1816}
1917
20- let rs = new MyReadable ( ) ;
18+ const rs = new MyReadable ( ) ;
2119rs . pipe ( process . stdout ) ;
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ const { Readable } = require ( 'stream' ) ;
4+
5+ class RGB extends Readable {
6+ constructor ( num ) {
7+ super ( ) ;
8+ this . #num = num ;
9+ }
10+
11+ _read ( ) {
12+ this . #pos++ > this . #num ? this . push ( null ) : this . push ( this . #rgb( ) ) ;
13+ }
14+
15+ #rgb( ) {
16+ let x = Math . round ( Math . random ( ) * 100 ) ;
17+ return x <= 60 ? 'R' : ( x <= 75 ? 'G' :'B' ) ;
18+ }
19+
20+ #num = 0 ;
21+ #pos = 0 ;
22+ }
23+
24+ const rs = new RGB ( 100 ) ;
25+ rs . pipe ( process . stdout ) ;
You can’t perform that action at this time.
0 commit comments