| 
1 | 1 | 'use strict';  | 
2 |  | -var common = require('../common');  | 
3 |  | -var assert = require('assert');  | 
4 |  | -var fs = require('fs');  | 
 | 2 | +const common = require('../common');  | 
 | 3 | +const assert = require('assert');  | 
 | 4 | +const fs = require('fs');  | 
5 | 5 | 
 
  | 
6 |  | -var stream = fs.createReadStream(__filename, {  | 
 | 6 | +const stream = fs.createReadStream(__filename, {  | 
7 | 7 |   bufferSize: 64  | 
8 | 8 | });  | 
9 |  | -var err = new Error('BAM');  | 
 | 9 | +const err = new Error('BAM');  | 
10 | 10 | 
 
  | 
11 |  | -stream.on('error', common.mustCall(function errorHandler(err_) {  | 
12 |  | -  console.error('error event');  | 
13 |  | -  process.nextTick(function() {  | 
14 |  | -    assert.equal(stream.fd, null);  | 
15 |  | -    assert.equal(err_, err);  | 
16 |  | -  });  | 
 | 11 | +stream.on('error', common.mustCall((err_) => {  | 
 | 12 | +  process.nextTick(common.mustCall(() => {  | 
 | 13 | +    assert.strictEqual(stream.fd, null);  | 
 | 14 | +    assert.strictEqual(err_, err);  | 
 | 15 | +  }));  | 
17 | 16 | }));  | 
18 | 17 | 
 
  | 
19 |  | -fs.close = common.mustCall(function(fd_, cb) {  | 
20 |  | -  assert.equal(fd_, stream.fd);  | 
 | 18 | +fs.close = common.mustCall((fd_, cb) => {  | 
 | 19 | +  assert.strictEqual(fd_, stream.fd);  | 
21 | 20 |   process.nextTick(cb);  | 
22 | 21 | });  | 
23 | 22 | 
 
  | 
24 |  | -var read = fs.read;  | 
 | 23 | +const read = fs.read;  | 
25 | 24 | fs.read = function() {  | 
26 | 25 |   // first time is ok.  | 
27 | 26 |   read.apply(fs, arguments);  | 
28 | 27 |   // then it breaks  | 
29 |  | -  fs.read = function() {  | 
30 |  | -    var cb = arguments[arguments.length - 1];  | 
31 |  | -    process.nextTick(function() {  | 
 | 28 | +  fs.read = common.mustCall(function() {  | 
 | 29 | +    const cb = arguments[arguments.length - 1];  | 
 | 30 | +    process.nextTick(() => {  | 
32 | 31 |       cb(err);  | 
33 | 32 |     });  | 
34 | 33 |     // and should not be called again!  | 
35 |  | -    fs.read = function() {  | 
 | 34 | +    fs.read = () => {  | 
36 | 35 |       throw new Error('BOOM!');  | 
37 | 36 |     };  | 
38 |  | -  };  | 
 | 37 | +  });  | 
39 | 38 | };  | 
40 | 39 | 
 
  | 
41 |  | -stream.on('data', function(buf) {  | 
42 |  | -  stream.on('data', common.fail);  // no more 'data' events should follow  | 
 | 40 | +stream.on('data', (buf) => {  | 
 | 41 | +  stream.on('data', () => common.fail("no more 'data' events should follow"));  | 
43 | 42 | });  | 
0 commit comments