@@ -11,38 +11,46 @@ const transformer = csv.transform(function(data){
11
11
} ) ;
12
12
const stringifier = csv . stringify ( ) ;
13
13
14
+ // Read generated CSV data and send it to the parser
14
15
generator . on ( 'readable' , function ( ) {
15
16
let data ; while ( data = generator . read ( ) ) {
16
17
parser . write ( data ) ;
17
18
}
18
19
} ) ;
20
+ // When generation is over, close the parser
19
21
generator . on ( 'end' , function ( ) {
20
22
parser . end ( )
21
23
} ) ;
22
24
25
+ // Read parsed records and send them to the transformer
23
26
parser . on ( 'readable' , function ( ) {
24
27
let data ; while ( data = parser . read ( ) ) {
25
28
transformer . write ( data ) ;
26
29
}
27
30
} ) ;
31
+ // When parsing is over, close the transformer
28
32
parser . on ( 'end' , function ( ) {
29
33
transformer . end ( )
30
34
} ) ;
31
35
36
+ // Read transformed records and send them to the stringifier
32
37
transformer . on ( 'readable' , function ( ) {
33
38
let data ; while ( data = transformer . read ( ) ) {
34
39
stringifier . write ( data ) ;
35
40
}
36
41
} ) ;
42
+ // When transformation is over, close the stringifier
37
43
transformer . on ( 'end' , function ( ) {
38
44
stringifier . end ( ) ;
39
45
} ) ;
40
46
47
+ // Read CSV data and print it to stdout
41
48
stringifier . on ( 'readable' , function ( ) {
42
49
let data ; while ( data = stringifier . read ( ) ) {
43
50
process . stdout . write ( data ) ;
44
51
}
45
52
} ) ;
53
+ // When stringifying is over, print a summary to stderr
46
54
generator . on ( 'end' , function ( ) {
47
- process . stdout . write ( '=> ' + i + ' records\n' ) ;
55
+ process . stderr . write ( '=> ' + i + ' records\n' ) ;
48
56
} ) ;
0 commit comments