Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

minor corrections from examining stream read positioning

Fix minor typos, one small refactor, and change emit() in a constructor
to a throw
  • Loading branch information...
commit f4c38cc54440457a316ec78849d62e6a36e6007e 1 parent 087d210
@tshinnic authored
Showing with 11 additions and 18 deletions.
  1. +11 −18 lib/fs.js
View
29 lib/fs.js
@@ -928,10 +928,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) {
@@ -962,9 +962,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
@@ -973,11 +973,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.
@@ -1022,10 +1017,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;
};
@@ -1132,7 +1127,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;
}
@@ -1141,8 +1136,6 @@ WriteStream.prototype.flush = function() {
var method = args.shift(),
cb = args.pop();
- var self = this;
-
args.push(function(err) {
self.busy = false;
@@ -1182,7 +1175,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);
@@ -1190,7 +1183,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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.