fs: remove undocumented .destroy callbacks

The destroy() method of fs.ReadStream and fs.WriteStream takes a callback.
It's a leftover from the node 0.1 days, undocumented and not part of the
streams API. Remove it.
This commit is contained in:
Ben Noordhuis 2012-08-06 00:45:30 +02:00
parent 624788df7e
commit 2f7e0f2da6
2 changed files with 9 additions and 35 deletions

View File

@ -1364,25 +1364,19 @@ ReadStream.prototype._emitData = function(d) {
}; };
ReadStream.prototype.destroy = function(cb) { ReadStream.prototype.destroy = function() {
var self = this; var self = this;
if (!this.readable) { if (!this.readable) return;
if (cb) process.nextTick(function() { cb(null); });
return;
}
this.readable = false; this.readable = false;
function close() { function close() {
fs.close(self.fd, function(err) { fs.close(self.fd, function(err) {
if (err) { if (err) {
if (cb) cb(err);
self.emit('error', err); self.emit('error', err);
return; } else {
}
if (cb) cb(null);
self.emit('close'); self.emit('close');
}
}); });
} }
@ -1570,25 +1564,19 @@ WriteStream.prototype.end = function(data, encoding, cb) {
this.flush(); this.flush();
}; };
WriteStream.prototype.destroy = function(cb) { WriteStream.prototype.destroy = function() {
var self = this; var self = this;
if (!this.writable) { if (!this.writable) return;
if (cb) process.nextTick(function() { cb(null); });
return;
}
this.writable = false; this.writable = false;
function close() { function close() {
fs.close(self.fd, function(err) { fs.close(self.fd, function(err) {
if (err) { if (err) {
if (cb) { cb(err); }
self.emit('error', err); self.emit('error', err);
return; } else {
}
if (cb) { cb(null); }
self.emit('close'); self.emit('close');
}
}); });
} }

View File

@ -34,7 +34,7 @@ var fs = require('fs');
var fn = path.join(common.fixturesDir, 'elipses.txt'); var fn = path.join(common.fixturesDir, 'elipses.txt');
var rangeFile = path.join(common.fixturesDir, 'x.txt'); var rangeFile = path.join(common.fixturesDir, 'x.txt');
var callbacks = { open: 0, end: 0, close: 0, destroy: 0 }; var callbacks = { open: 0, end: 0, close: 0 };
var paused = false; var paused = false;
@ -82,17 +82,6 @@ file.on('close', function() {
//assert.equal(fs.readFileSync(fn), fileContent); //assert.equal(fs.readFileSync(fn), fileContent);
}); });
var file2 = fs.createReadStream(fn);
file2.destroy(function(err) {
assert.ok(!err);
callbacks.destroy++;
file2.destroy(function(err) {
assert.ok(!err);
callbacks.destroy++;
});
});
var file3 = fs.createReadStream(fn, {encoding: 'utf8'}); var file3 = fs.createReadStream(fn, {encoding: 'utf8'});
file3.length = 0; file3.length = 0;
file3.on('data', function(data) { file3.on('data', function(data) {
@ -112,10 +101,7 @@ file3.on('close', function() {
process.on('exit', function() { process.on('exit', function() {
assert.equal(1, callbacks.open); assert.equal(1, callbacks.open);
assert.equal(1, callbacks.end); assert.equal(1, callbacks.end);
assert.equal(2, callbacks.destroy);
assert.equal(2, callbacks.close); assert.equal(2, callbacks.close);
assert.equal(30000, file.length); assert.equal(30000, file.length);
assert.equal(10000, file3.length); assert.equal(10000, file3.length);
}); });