Bug 347420 - networks.txt ignored if last line doesn't end in \n

r=silver@warwickcompsoc.co.uk (James Ross)
ChatZilla Only.
This commit is contained in:
gijskruitbosch%gmail.com 2006-11-12 00:26:36 +00:00
parent a285a693d2
commit 1ed63be97a
3 changed files with 30 additions and 12 deletions

View File

@ -368,21 +368,27 @@ function fo_write(buf)
return this.outputStream.write(buf, buf.length);
}
// Will return null if there is no more data in the file.
// Will block until it has some data to return.
// Will return an empty string if there is data, but it couldn't be read.
LocalFile.prototype.read =
function fo_read(max)
{
if (!("inputStream" in this))
throw "file not open for reading.";
var av = this.inputStream.available();
if (typeof max == "undefined")
max = av;
max = this.inputStream.available();
if (!av)
return null;
var rv = this.inputStream.read(max);
return rv;
try
{
var rv = this.inputStream.read(max);
return (rv != "") ? rv : null;
}
catch (ex)
{
return "";
}
}
LocalFile.prototype.close =

View File

@ -226,11 +226,20 @@ function ts_deserialize()
{
if (this._lines.length == 0)
{
this._buffer += this._fileStream.read();
// Got more data in the buffer, so split into lines.
// The last one doesn't count - the rest get added to the full list.
var newData = this._fileStream.read();
if (newData)
this._buffer += newData;
else if (this._buffer.length == 0)
break;
// Got more data in the buffer, so split into lines. Unless we're
// done, the last one might not be complete yet, so save that one.
var lines = this._buffer.split(/[\r\n]+/);
this._buffer = lines.pop();
if (!newData)
this._buffer = "";
else
this._buffer = lines.pop();
this._lines = this._lines.concat(lines);
if (this._lines.length == 0)
break;

View File

@ -439,7 +439,10 @@ function doCurrentStatusRun()
else if (state.timeTaken < 0.75 * STATE_DELAY)
state.loadChunk += 100;
state.loadedSoFar += state.loadChunk;
state.loadPendingData += state.loadFile.read(state.loadChunk);
var newChunk = state.loadFile.read(state.loadChunk);
if (newChunk)
state.loadPendingData += newChunk;
while (state.loadPendingData.indexOf("\n") != -1)
{