mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
971 B
43 lines
971 B
12 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
|
var fs = require('fs');
|
||
|
|
||
12 years ago
|
var stream = fs.createReadStream(__filename, {
|
||
12 years ago
|
bufferSize: 64
|
||
12 years ago
|
});
|
||
12 years ago
|
var err = new Error('BAM');
|
||
|
|
||
12 years ago
|
stream.on('error', common.mustCall(function errorHandler(err_) {
|
||
|
console.error('error event');
|
||
|
process.nextTick(function() {
|
||
|
assert.equal(stream.fd, null);
|
||
|
assert.equal(err_, err);
|
||
|
});
|
||
|
}));
|
||
|
|
||
|
fs.close = common.mustCall(function(fd_, cb) {
|
||
|
assert.equal(fd_, stream.fd);
|
||
|
process.nextTick(cb);
|
||
|
});
|
||
12 years ago
|
|
||
12 years ago
|
var read = fs.read;
|
||
|
fs.read = function() {
|
||
|
// first time is ok.
|
||
|
read.apply(fs, arguments);
|
||
|
// then it breaks
|
||
12 years ago
|
fs.read = function() {
|
||
|
var cb = arguments[arguments.length - 1];
|
||
|
process.nextTick(function() {
|
||
|
cb(err);
|
||
|
});
|
||
12 years ago
|
// and should not be called again!
|
||
|
fs.read = function() {
|
||
|
throw new Error('BOOM!');
|
||
|
};
|
||
12 years ago
|
};
|
||
12 years ago
|
};
|
||
12 years ago
|
|
||
12 years ago
|
stream.on('data', function(buf) {
|
||
12 years ago
|
stream.on('data', assert.fail); // no more 'data' events should follow
|
||
|
});
|