Browse Source

fs: minor corrections from examining stream read positioning

Fix minor typos, one small refactor, and change emit() in a constructor
to a throw
Thomas Shinnick 13 years ago
committed by koichik
parent
commit
e4ebeb630e
  1. 29
      lib/fs.js

29
lib/fs.js

@ -931,10 +931,10 @@ var ReadStream = fs.ReadStream = function(path, options) {
}
if (this.start > this.end) {
this.emit('error', new Error('start must be <= end'));
} else {
this._firstRead = true;
throw new Error('start must be <= end');
}
this.pos = this.start;
}
if (this.fd !== null) {
@ -965,9 +965,9 @@ ReadStream.prototype.setEncoding = function(encoding) {
ReadStream.prototype._read = function() {
var self = this;
if (!self.readable || self.paused || self.reading) return;
if (!this.readable || this.paused || this.reading) return;
self.reading = true;
this.reading = true;
if (!pool || pool.length - pool.used < kMinPoolSpace) {
// discard the old pool. Can't add to the free list because
@ -976,11 +976,6 @@ ReadStream.prototype._read = function() {
allocNewPool();
}
if (self.start !== undefined && self._firstRead) {
self.pos = self.start;
self._firstRead = false;
}
// Grab another reference to the pool in the case that while we're in the
// thread pool another read() finishes up the pool, and allocates a new
// one.
@ -1025,10 +1020,10 @@ ReadStream.prototype._read = function() {
self._read();
}
fs.read(self.fd, pool, pool.used, toRead, self.pos, afterRead);
fs.read(this.fd, pool, pool.used, toRead, this.pos, afterRead);
if (self.pos !== undefined) {
self.pos += toRead;
if (this.pos !== undefined) {
this.pos += toRead;
}
pool.used += toRead;
};
@ -1135,7 +1130,7 @@ WriteStream.prototype.flush = function() {
var args = this._queue.shift();
if (!args) {
if (this.drainable) { self.emit('drain'); }
if (this.drainable) { this.emit('drain'); }
return;
}
@ -1144,8 +1139,6 @@ WriteStream.prototype.flush = function() {
var method = args.shift(),
cb = args.pop();
var self = this;
args.push(function(err) {
self.busy = false;
@ -1185,7 +1178,7 @@ WriteStream.prototype.flush = function() {
// Inject the file pointer
if (method !== fs.open) {
args.unshift(self.fd);
args.unshift(this.fd);
}
method.apply(this, args);
@ -1193,7 +1186,7 @@ WriteStream.prototype.flush = function() {
WriteStream.prototype.write = function(data) {
if (!this.writable) {
this.emit("error", new Error('stream not writable'));
this.emit('error', new Error('stream not writable'));
return false;
}

Loading…
Cancel
Save