From e7a1fa129372398631c9f05d85389d6beebc518b Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 27 Apr 2010 18:51:41 -0700 Subject: [PATCH] fs.FileWriteStream -> fs.WriteStream, fs.FileReadStream -> fs.ReadStream --- doc/api.markdown | 12 ++++++------ lib/fs.js | 45 ++++++++++++++++++++++++--------------------- src/node.js | 4 ++-- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/doc/api.markdown b/doc/api.markdown index 3459e12..a21d2d5 100644 --- a/doc/api.markdown +++ b/doc/api.markdown @@ -1455,13 +1455,13 @@ Objects returned from `fs.stat()` and `fs.lstat()` are of this type. - `stats.isSocket()` -## fs.FileReadStream +## fs.ReadStream -`FileReadStream` is a readable stream. +`ReadStream` is a readable stream. ### fs.createReadStream(path, [options]) -Returns a new FileReadStream object. +Returns a new ReadStream object. `options` is an object with the following defaults: @@ -1490,13 +1490,13 @@ Resumes the stream. Together with `pause()` this useful to throttle reading. Allows to close the stream before the `'end'` is reached. No more events other than `'close'` will be fired after this method has been called. -## fs.FileWriteStream +## fs.WriteStream -`FileWriteStream` is a writable stream. +`WriteStream` is a writable stream. ### fs.createWriteStream(path, [options]) -Returns a new FileWriteStream object. +Returns a new WriteStream object. `options` is an object with the following defaults: { 'flags': 'w' diff --git a/lib/fs.js b/lib/fs.js index 15c37e0..8d17c7f 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -474,10 +474,10 @@ fs.realpath = function (path, callback) { } fs.createReadStream = function(path, options) { - return new FileReadStream(path, options); + return new ReadStream(path, options); }; -var FileReadStream = fs.FileReadStream = function(path, options) { +var ReadStream = fs.ReadStream = function(path, options) { events.EventEmitter.call(this); this.path = path; @@ -516,13 +516,15 @@ var FileReadStream = fs.FileReadStream = function(path, options) { self._read(); }); }; -sys.inherits(FileReadStream, events.EventEmitter); +sys.inherits(ReadStream, events.EventEmitter); -FileReadStream.prototype.setEncoding = function(encoding) { +fs.FileReadStream = fs.ReadStream; // support the legacy name + +ReadStream.prototype.setEncoding = function(encoding) { this.encoding = encoding; }; -FileReadStream.prototype._read = function () { +ReadStream.prototype._read = function () { var self = this; if (!self.readable || self.paused) return; @@ -562,16 +564,16 @@ FileReadStream.prototype._read = function () { var readStreamForceCloseWarning; -FileReadStream.prototype.forceClose = function (cb) { +ReadStream.prototype.forceClose = function (cb) { if (!readStreamForceCloseWarning) { - readStreamForceCloseWarning = "FileReadStream.prototype.forceClose renamed to destroy()"; + readStreamForceCloseWarning = "ReadStream.prototype.forceClose renamed to destroy()"; sys.error(readStreamForceCloseWarning); } return this.destroy(cb); } -FileReadStream.prototype.destroy = function (cb) { +ReadStream.prototype.destroy = function (cb) { var self = this; this.readable = false; @@ -600,12 +602,12 @@ FileReadStream.prototype.destroy = function (cb) { }; -FileReadStream.prototype.pause = function() { +ReadStream.prototype.pause = function() { this.paused = true; }; -FileReadStream.prototype.resume = function() { +ReadStream.prototype.resume = function() { this.paused = false; if (this.buffer) { @@ -619,10 +621,10 @@ FileReadStream.prototype.resume = function() { fs.createWriteStream = function(path, options) { - return new FileWriteStream(path, options); + return new WriteStream(path, options); }; -var FileWriteStream = fs.FileWriteStream = function(path, options) { +var WriteStream = fs.WriteStream = function(path, options) { events.EventEmitter.call(this); this.path = path; @@ -650,11 +652,12 @@ var FileWriteStream = fs.FileWriteStream = function(path, options) { this.flush(); } }; -sys.inherits(FileWriteStream, events.EventEmitter); +sys.inherits(WriteStream, events.EventEmitter); +fs.FileWriteStream = fs.WriteStream; // support the legacy name -FileWriteStream.prototype.flush = function () { +WriteStream.prototype.flush = function () { if (this.busy) return; var self = this; @@ -710,7 +713,7 @@ FileWriteStream.prototype.flush = function () { }; -FileWriteStream.prototype.write = function(data, encoding) { +WriteStream.prototype.write = function(data, encoding) { if (!this.writeable) { throw new Error('stream not writeable'); } @@ -726,16 +729,16 @@ FileWriteStream.prototype.write = function(data, encoding) { var writeStreamCloseWarning; -FileWriteStream.prototype.close = function (cb) { +WriteStream.prototype.close = function (cb) { if (!writeStreamCloseWarning) { - writeStreamCloseWarning = "FileWriteStream.prototype.close renamed to end()"; + writeStreamCloseWarning = "WriteStream.prototype.close renamed to end()"; sys.error(writeStreamCloseWarning); } return this.end(cb); } -FileWriteStream.prototype.end = function (cb) { +WriteStream.prototype.end = function (cb) { this.writeable = false; this._queue.push([fs.close, cb]); this.flush(); @@ -744,16 +747,16 @@ FileWriteStream.prototype.end = function (cb) { var writeStreamForceCloseWarning; -FileWriteStream.prototype.forceClose = function (cb) { +WriteStream.prototype.forceClose = function (cb) { if (!writeStreamForceCloseWarning) { - writeStreamForceCloseWarning = "FileWriteStream.prototype.forceClose renamed to destroy()"; + writeStreamForceCloseWarning = "WriteStream.prototype.forceClose renamed to destroy()"; sys.error(writeStreamForceCloseWarning); } return this.destroy(cb); } -FileWriteStream.prototype.forceClose = function (cb) { +WriteStream.prototype.forceClose = function (cb) { this.writeable = false; fs.close(self.fd, function(err) { if (err) { diff --git a/src/node.js b/src/node.js index e6875d8..1de5563 100644 --- a/src/node.js +++ b/src/node.js @@ -136,7 +136,7 @@ process.__defineGetter__('stdout', function () { fd = binding.stdoutFD; if (binding.isStdoutBlocking()) { - stdout = new fs.FileWriteStream(null, {fd: fd}); + stdout = new fs.WriteStream(null, {fd: fd}); } else { stdout = new net.Stream(fd); // FIXME Should probably have an option in net.Stream to create a stream from @@ -161,7 +161,7 @@ process.openStdin = function () { stdin = new net.Stream(fd); stdin.readable = true; } else { - stdin = new fs.FileReadStream(null, {fd: fd}); + stdin = new fs.ReadStream(null, {fd: fd}); } stdin.resume(); -- 2.7.4