}
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) {
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
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.
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;
};
var args = this._queue.shift();
if (!args) {
- if (this.drainable) { self.emit('drain'); }
+ if (this.drainable) { this.emit('drain'); }
return;
}
var method = args.shift(),
cb = args.pop();
- var self = this;
-
args.push(function(err) {
self.busy = false;
// Inject the file pointer
if (method !== fs.open) {
- args.unshift(self.fd);
+ args.unshift(this.fd);
}
method.apply(this, args);
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;
}