added measure against half-flushed objects

This commit is contained in:
FinnHornhoover 2023-10-18 15:39:44 +03:00
parent 600b33a230
commit 04aea6059e
1 changed files with 12 additions and 4 deletions

View File

@ -342,6 +342,7 @@ function handleCache(mode, versionString, cacheMode, callback) {
path.dirname(versions[0].url); path.dirname(versions[0].url);
var lastSizes = {}; var lastSizes = {};
var buf = "";
storageLoadingStart(versionString, cacheMode); storageLoadingStart(versionString, cacheMode);
@ -349,12 +350,19 @@ function handleCache(mode, versionString, cacheMode, callback) {
sock.setEncoding("utf8"); sock.setEncoding("utf8");
sock.on("data", function (data) { sock.on("data", function (data) {
data.split("\n").forEach(function (sizeString) { buf += data;
if (sizeString === "") return;
lastSizes = JSON.parse(sizeString); var end = buf.indexOf("\n");
while (end > 0) {
var sub = buf.substring(0, end);
buf = buf.substring(end + 1);
lastSizes = JSON.parse(sub);
storageLoadingUpdate(lastSizes); storageLoadingUpdate(lastSizes);
});
end = buf.indexOf("\n");
}
}); });
}); });