fs.FileWriteStream -> fs.WriteStream, fs.FileReadStream -> fs.ReadStream

This commit is contained in:
Ryan Dahl 2010-04-27 18:51:41 -07:00
parent 5aea12b4c4
commit e7a1fa1293
3 changed files with 33 additions and 30 deletions

View File

@ -1455,13 +1455,13 @@ Objects returned from `fs.stat()` and `fs.lstat()` are of this type.
- `stats.isSocket()` - `stats.isSocket()`
## fs.FileReadStream ## fs.ReadStream
`FileReadStream` is a readable stream. `ReadStream` is a readable stream.
### fs.createReadStream(path, [options]) ### fs.createReadStream(path, [options])
Returns a new FileReadStream object. Returns a new ReadStream object.
`options` is an object with the following defaults: `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 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. 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]) ### fs.createWriteStream(path, [options])
Returns a new FileWriteStream object. Returns a new WriteStream object.
`options` is an object with the following defaults: `options` is an object with the following defaults:
{ 'flags': 'w' { 'flags': 'w'

View File

@ -474,10 +474,10 @@ fs.realpath = function (path, callback) {
} }
fs.createReadStream = function(path, options) { 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); events.EventEmitter.call(this);
this.path = path; this.path = path;
@ -516,13 +516,15 @@ var FileReadStream = fs.FileReadStream = function(path, options) {
self._read(); 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; this.encoding = encoding;
}; };
FileReadStream.prototype._read = function () { ReadStream.prototype._read = function () {
var self = this; var self = this;
if (!self.readable || self.paused) return; if (!self.readable || self.paused) return;
@ -562,16 +564,16 @@ FileReadStream.prototype._read = function () {
var readStreamForceCloseWarning; var readStreamForceCloseWarning;
FileReadStream.prototype.forceClose = function (cb) { ReadStream.prototype.forceClose = function (cb) {
if (!readStreamForceCloseWarning) { if (!readStreamForceCloseWarning) {
readStreamForceCloseWarning = "FileReadStream.prototype.forceClose renamed to destroy()"; readStreamForceCloseWarning = "ReadStream.prototype.forceClose renamed to destroy()";
sys.error(readStreamForceCloseWarning); sys.error(readStreamForceCloseWarning);
} }
return this.destroy(cb); return this.destroy(cb);
} }
FileReadStream.prototype.destroy = function (cb) { ReadStream.prototype.destroy = function (cb) {
var self = this; var self = this;
this.readable = false; this.readable = false;
@ -600,12 +602,12 @@ FileReadStream.prototype.destroy = function (cb) {
}; };
FileReadStream.prototype.pause = function() { ReadStream.prototype.pause = function() {
this.paused = true; this.paused = true;
}; };
FileReadStream.prototype.resume = function() { ReadStream.prototype.resume = function() {
this.paused = false; this.paused = false;
if (this.buffer) { if (this.buffer) {
@ -619,10 +621,10 @@ FileReadStream.prototype.resume = function() {
fs.createWriteStream = function(path, options) { 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); events.EventEmitter.call(this);
this.path = path; this.path = path;
@ -650,11 +652,12 @@ var FileWriteStream = fs.FileWriteStream = function(path, options) {
this.flush(); this.flush();
} }
}; };
sys.inherits(FileWriteStream, events.EventEmitter); sys.inherits(WriteStream, events.EventEmitter);
fs.FileWriteStream = fs.WriteStream; // support the legacy name
WriteStream.prototype.flush = function () {
FileWriteStream.prototype.flush = function () {
if (this.busy) return; if (this.busy) return;
var self = this; 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) { if (!this.writeable) {
throw new Error('stream not writeable'); throw new Error('stream not writeable');
} }
@ -726,16 +729,16 @@ FileWriteStream.prototype.write = function(data, encoding) {
var writeStreamCloseWarning; var writeStreamCloseWarning;
FileWriteStream.prototype.close = function (cb) { WriteStream.prototype.close = function (cb) {
if (!writeStreamCloseWarning) { if (!writeStreamCloseWarning) {
writeStreamCloseWarning = "FileWriteStream.prototype.close renamed to end()"; writeStreamCloseWarning = "WriteStream.prototype.close renamed to end()";
sys.error(writeStreamCloseWarning); sys.error(writeStreamCloseWarning);
} }
return this.end(cb); return this.end(cb);
} }
FileWriteStream.prototype.end = function (cb) { WriteStream.prototype.end = function (cb) {
this.writeable = false; this.writeable = false;
this._queue.push([fs.close, cb]); this._queue.push([fs.close, cb]);
this.flush(); this.flush();
@ -744,16 +747,16 @@ FileWriteStream.prototype.end = function (cb) {
var writeStreamForceCloseWarning; var writeStreamForceCloseWarning;
FileWriteStream.prototype.forceClose = function (cb) { WriteStream.prototype.forceClose = function (cb) {
if (!writeStreamForceCloseWarning) { if (!writeStreamForceCloseWarning) {
writeStreamForceCloseWarning = "FileWriteStream.prototype.forceClose renamed to destroy()"; writeStreamForceCloseWarning = "WriteStream.prototype.forceClose renamed to destroy()";
sys.error(writeStreamForceCloseWarning); sys.error(writeStreamForceCloseWarning);
} }
return this.destroy(cb); return this.destroy(cb);
} }
FileWriteStream.prototype.forceClose = function (cb) { WriteStream.prototype.forceClose = function (cb) {
this.writeable = false; this.writeable = false;
fs.close(self.fd, function(err) { fs.close(self.fd, function(err) {
if (err) { if (err) {

View File

@ -136,7 +136,7 @@ process.__defineGetter__('stdout', function () {
fd = binding.stdoutFD; fd = binding.stdoutFD;
if (binding.isStdoutBlocking()) { if (binding.isStdoutBlocking()) {
stdout = new fs.FileWriteStream(null, {fd: fd}); stdout = new fs.WriteStream(null, {fd: fd});
} else { } else {
stdout = new net.Stream(fd); stdout = new net.Stream(fd);
// FIXME Should probably have an option in net.Stream to create a stream from // 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 = new net.Stream(fd);
stdin.readable = true; stdin.readable = true;
} else { } else {
stdin = new fs.FileReadStream(null, {fd: fd}); stdin = new fs.ReadStream(null, {fd: fd});
} }
stdin.resume(); stdin.resume();