diff --git a/lib/fs.js b/lib/fs.js index e12a82af04..705d2232b3 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -623,7 +623,7 @@ var ReadStream = fs.ReadStream = function(path, options) { this[key] = options[key]; } - if (this.start || this.end) { + if (this.start !== undefined || this.end !== undefined) { if (this.start === undefined || this.end === undefined) { this.emit('error', new Error('Both start and end are needed for range streaming.')); @@ -671,7 +671,7 @@ ReadStream.prototype._read = function () { allocNewPool(); } - if(this.start && this.firstRead) { + if (this.start !== undefined && this.firstRead) { this.pos = this.start; this.firstRead = false; } @@ -683,7 +683,7 @@ ReadStream.prototype._read = function () { var toRead = Math.min(pool.length - pool.used, this.bufferSize); var start = pool.used; - if(this.pos) { + if (this.pos !== undefined) { toRead = Math.min(this.end - this.pos + 1, toRead); } @@ -721,7 +721,7 @@ ReadStream.prototype._read = function () { fs.read(self.fd, pool, pool.used, toRead, this.pos, afterRead); - if(self.pos) { + if (self.pos !== undefined) { self.pos += toRead; } pool.used += toRead; diff --git a/test/simple/test-fs-read-stream.js b/test/simple/test-fs-read-stream.js index b008e9153c..ab8cbc5a4e 100644 --- a/test/simple/test-fs-read-stream.js +++ b/test/simple/test-fs-read-stream.js @@ -110,3 +110,14 @@ try { } catch(e) { assert.equal(e.message, 'Both start and end are needed for range streaming.'); } + +var stream = fs.createReadStream(rangeFile, { start: 0, end: 0 }); +stream.data = ''; + +stream.on('data', function(chunk){ + stream.data += chunk; +}); + +stream.on('end', function(){ + assert.equal('x', stream.data); +}); \ No newline at end of file