mirror of https://github.com/nodejs/node.git
Fixed fs.ReadStream() start: 0 bug
parent
e227441248
commit
893ebe7230
|
@ -623,7 +623,7 @@ var ReadStream = fs.ReadStream = function(path, options) {
|
||||||
this[key] = options[key];
|
this[key] = options[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.start || this.end) {
|
if (this.start !== undefined || this.end !== undefined) {
|
||||||
if (this.start === undefined || this.end === undefined) {
|
if (this.start === undefined || this.end === undefined) {
|
||||||
this.emit('error',
|
this.emit('error',
|
||||||
new Error('Both start and end are needed for range streaming.'));
|
new Error('Both start and end are needed for range streaming.'));
|
||||||
|
@ -671,7 +671,7 @@ ReadStream.prototype._read = function () {
|
||||||
allocNewPool();
|
allocNewPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.start && this.firstRead) {
|
if (this.start !== undefined && this.firstRead) {
|
||||||
this.pos = this.start;
|
this.pos = this.start;
|
||||||
this.firstRead = false;
|
this.firstRead = false;
|
||||||
}
|
}
|
||||||
|
@ -683,7 +683,7 @@ ReadStream.prototype._read = function () {
|
||||||
var toRead = Math.min(pool.length - pool.used, this.bufferSize);
|
var toRead = Math.min(pool.length - pool.used, this.bufferSize);
|
||||||
var start = pool.used;
|
var start = pool.used;
|
||||||
|
|
||||||
if(this.pos) {
|
if (this.pos !== undefined) {
|
||||||
toRead = Math.min(this.end - this.pos + 1, toRead);
|
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);
|
fs.read(self.fd, pool, pool.used, toRead, this.pos, afterRead);
|
||||||
|
|
||||||
if(self.pos) {
|
if (self.pos !== undefined) {
|
||||||
self.pos += toRead;
|
self.pos += toRead;
|
||||||
}
|
}
|
||||||
pool.used += toRead;
|
pool.used += toRead;
|
||||||
|
|
|
@ -110,3 +110,14 @@ try {
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
assert.equal(e.message, 'Both start and end are needed for range streaming.');
|
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);
|
||||||
|
});
|
Loading…
Reference in New Issue