Skip to content

Commit

Permalink
Removed range read optimization as it doesn't work with libeio.
Browse files Browse the repository at this point in the history
  • Loading branch information
cskr authored and ry committed Nov 16, 2010
1 parent 67cc6d7 commit 4e0c7dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions lib/fs.js
Expand Up @@ -638,7 +638,7 @@ var ReadStream = fs.ReadStream = function(path, options) {
} else if (this.start > this.end) {
this.emit('error', new Error('start must be <= end'));
} else {
this.firstRead = true;
this._firstRead = true;
}
}

Expand Down Expand Up @@ -679,8 +679,9 @@ ReadStream.prototype._read = function () {
allocNewPool();
}

if (self.start !== undefined && self.firstRead) {
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
Expand Down Expand Up @@ -726,10 +727,7 @@ ReadStream.prototype._read = function () {
self._read();
}

// pass null for position after we've seeked to the start of a range read
// always pass null on a non-range read
fs.read(self.fd, pool, pool.used, toRead, (self.firstRead ? self.pos : null), afterRead);
self.firstRead = false;
fs.read(self.fd, pool, pool.used, toRead, self.pos, afterRead);

if (self.pos !== undefined) {
self.pos += toRead;
Expand Down
8 changes: 4 additions & 4 deletions test/simple/test-fs-read-stream.js
Expand Up @@ -87,13 +87,13 @@ process.addListener('exit', function() {
assert.equal(10000, file3.length);
});

var file4 = fs.createReadStream(rangeFile, {start: 1, end: 2});
var file4 = fs.createReadStream(rangeFile, {bufferSize: 1, start: 1, end: 2});
var contentRead = '';
file4.addListener('data', function(data) {
contentRead += data.toString('utf-8');
contentRead += data.toString('utf-8');
});
file4.addListener('end', function(data) {
assert.equal(contentRead, 'yz');
assert.equal(contentRead, 'yz');
});

try {
Expand All @@ -119,4 +119,4 @@ stream.on('data', function(chunk){

stream.on('end', function(){
assert.equal('x', stream.data);
});
});

0 comments on commit 4e0c7dd

Please sign in to comment.