FIX: LineReader.hasNextLine go to an endless loop
LineReader.hasNextLine will go to an endless loop when buffer is empty or file not end with \n
This commit is contained in:
parent
92a4dffb11
commit
48aa600052
1 changed files with 5 additions and 3 deletions
|
|
@ -368,9 +368,12 @@ exports.LineReader.prototype = {
|
||||||
var res = fs.readSync(this.fd, this.bufferSize, position, "ascii");
|
var res = fs.readSync(this.fd, this.bufferSize, position, "ascii");
|
||||||
|
|
||||||
this.buffer += res[0];
|
this.buffer += res[0];
|
||||||
if(res[1] === 0) return -1;
|
if(res[1] === 0) {
|
||||||
|
this.currentPosition = -1;
|
||||||
|
} else {
|
||||||
this.currentPosition = position + res[1];
|
this.currentPosition = position + res[1];
|
||||||
|
}
|
||||||
|
|
||||||
return this.currentPosition;
|
return this.currentPosition;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -378,7 +381,6 @@ exports.LineReader.prototype = {
|
||||||
while(this.buffer.indexOf('\n') === -1) {
|
while(this.buffer.indexOf('\n') === -1) {
|
||||||
this.getBufferAndSetCurrentPosition(this.currentPosition);
|
this.getBufferAndSetCurrentPosition(this.currentPosition);
|
||||||
if(this.currentPosition === -1) return false;
|
if(this.currentPosition === -1) return false;
|
||||||
if(this.buffer.length === 0) return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.buffer.indexOf("\n") > -1) return true;
|
if(this.buffer.indexOf("\n") > -1) return true;
|
||||||
|
|
|
||||||
Reference in a new issue