|
|
@ -615,6 +615,16 @@ var ReadStream = fs.ReadStream = function(path, options) { |
|
|
|
this[key] = options[key]; |
|
|
|
} |
|
|
|
|
|
|
|
if(this.start || this.end) { |
|
|
|
if(this.start === undefined || this.end === undefined) { |
|
|
|
self.emit('error', new Error('Both start and end are needed for range streaming.')); |
|
|
|
} else if(this.start > this.end) { |
|
|
|
self.emit('error', new Error('start must be <= end')); |
|
|
|
} else { |
|
|
|
this.firstRead = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (this.fd !== null) { |
|
|
|
return; |
|
|
|
} |
|
|
@ -653,6 +663,11 @@ ReadStream.prototype._read = function () { |
|
|
|
allocNewPool(); |
|
|
|
} |
|
|
|
|
|
|
|
if(this.start && this.firstRead) { |
|
|
|
this.pos = this.start; |
|
|
|
this.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.
|
|
|
@ -660,6 +675,10 @@ ReadStream.prototype._read = function () { |
|
|
|
var toRead = Math.min(pool.length - pool.used, this.bufferSize); |
|
|
|
var start = pool.used; |
|
|
|
|
|
|
|
if(this.pos) { |
|
|
|
toRead = Math.min(this.end - this.pos + 1, toRead); |
|
|
|
} |
|
|
|
|
|
|
|
function afterRead (err, bytesRead) { |
|
|
|
if (err) { |
|
|
|
self.emit('error', err); |
|
|
@ -692,7 +711,11 @@ ReadStream.prototype._read = function () { |
|
|
|
self._read(); |
|
|
|
} |
|
|
|
|
|
|
|
fs.read(self.fd, pool, pool.used, toRead, undefined, afterRead); |
|
|
|
fs.read(self.fd, pool, pool.used, toRead, this.pos, afterRead); |
|
|
|
|
|
|
|
if(self.pos) { |
|
|
|
self.pos += toRead; |
|
|
|
} |
|
|
|
pool.used += toRead; |
|
|
|
}; |
|
|
|
|
|
|
|