From 2f7e0f2da6a5c1be7ed6c79eca6c723d1b341aff Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 6 Aug 2012 00:45:30 +0200 Subject: [PATCH] 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. --- lib/fs.js | 28 ++++++++-------------------- test/simple/test-fs-read-stream.js | 16 +--------------- 2 files changed, 9 insertions(+), 35 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index d53c3605cf0..31e36908fdb 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1364,25 +1364,19 @@ ReadStream.prototype._emitData = function(d) { }; -ReadStream.prototype.destroy = function(cb) { +ReadStream.prototype.destroy = function() { var self = this; - if (!this.readable) { - if (cb) process.nextTick(function() { cb(null); }); - return; - } + if (!this.readable) return; this.readable = false; function close() { fs.close(self.fd, function(err) { if (err) { - if (cb) cb(err); self.emit('error', err); - return; + } else { + self.emit('close'); } - - if (cb) cb(null); - self.emit('close'); }); } @@ -1570,25 +1564,19 @@ WriteStream.prototype.end = function(data, encoding, cb) { this.flush(); }; -WriteStream.prototype.destroy = function(cb) { +WriteStream.prototype.destroy = function() { var self = this; - if (!this.writable) { - if (cb) process.nextTick(function() { cb(null); }); - return; - } + if (!this.writable) return; this.writable = false; function close() { fs.close(self.fd, function(err) { if (err) { - if (cb) { cb(err); } self.emit('error', err); - return; + } else { + self.emit('close'); } - - if (cb) { cb(null); } - self.emit('close'); }); } diff --git a/test/simple/test-fs-read-stream.js b/test/simple/test-fs-read-stream.js index d500fc45ea8..71cff2c059f 100644 --- a/test/simple/test-fs-read-stream.js +++ b/test/simple/test-fs-read-stream.js @@ -34,7 +34,7 @@ var fs = require('fs'); var fn = path.join(common.fixturesDir, 'elipses.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; @@ -82,17 +82,6 @@ file.on('close', function() { //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'}); file3.length = 0; file3.on('data', function(data) { @@ -112,10 +101,7 @@ file3.on('close', function() { process.on('exit', function() { assert.equal(1, callbacks.open); assert.equal(1, callbacks.end); - assert.equal(2, callbacks.destroy); - assert.equal(2, callbacks.close); - assert.equal(30000, file.length); assert.equal(10000, file3.length); });