@@ -20,9 +20,7 @@ fs.createReadStream('ex.txt')
20
20
callback ()
21
21
}))
22
22
.pipe (fs .createWriteStream (' out.txt' ))
23
- .on (' finish' , function () {
24
- doSomethingSpecial ()
25
- })
23
+ .on (' finish' , () => doSomethingSpecial ())
26
24
```
27
25
28
26
Or object streams:
@@ -42,10 +40,10 @@ fs.createReadStream('data.csv')
42
40
43
41
callback ()
44
42
}))
45
- .on (' data' , function (data ) {
43
+ .on (' data' , (data ) => {
46
44
all .push (data)
47
45
})
48
- .on (' end' , function () {
46
+ .on (' end' , () => {
49
47
doSomethingSpecial (all)
50
48
})
51
49
```
@@ -67,7 +65,7 @@ The `options` argument is first, unlike standard convention, because if I'm pass
67
65
``` js
68
66
fs .createReadStream (' /tmp/important.dat' )
69
67
.pipe (through2 ({ objectMode: true , allowHalfOpen: false },
70
- function (chunk , enc , cb ) {
68
+ (chunk , enc , cb ) => {
71
69
cb (null , ' wut?' ) // note we can use the second argument on the callback
72
70
// to provide data as an alternative to this.push('wut?')
73
71
}
@@ -92,7 +90,7 @@ The optional `flushFunction` is provided as the last argument (2nd or 3rd, depen
92
90
` ` ` js
93
91
fs .createReadStream (' /tmp/important.dat' )
94
92
.pipe (through2 (
95
- function (chunk , enc , cb ) { cb (null , chunk) } , // transform is a noop
93
+ (chunk , enc , cb ) => cb (null , chunk), // transform is a noop
96
94
function (cb ) { // flush function
97
95
this .push (' tacking on an extra buffer to the end' );
98
96
cb ();
0 commit comments