From 914ff78df600a26a71b3ce01cd4ddee5006709cd Mon Sep 17 00:00:00 2001 From: Evan Larkin Date: Sun, 26 Sep 2010 22:31:09 -0500 Subject: [PATCH] fs.ReadStream: Passing null for file position on all reads except the first read of a range read. --- lib/fs.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 0bef4227be..286dea2654 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -683,9 +683,8 @@ ReadStream.prototype._read = function () { allocNewPool(); } - if (this.start !== undefined && this.firstRead) { - this.pos = this.start; - this.firstRead = false; + if (self.start !== undefined && self.firstRead) { + self.pos = self.start; } // Grab another reference to the pool in the case that while we're in the @@ -731,7 +730,10 @@ ReadStream.prototype._read = function () { self._read(); } - fs.read(self.fd, pool, pool.used, toRead, this.pos, afterRead); + // 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; if (self.pos !== undefined) { self.pos += toRead;