From e74106e13737db64478314498f64ee0de6df85b0 Mon Sep 17 00:00:00 2001 From: FinnHornhoover Date: Wed, 18 Oct 2023 15:39:44 +0300 Subject: [PATCH] added measure against half-flushed objects --- assets/js/server-selector.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/assets/js/server-selector.js b/assets/js/server-selector.js index bdd3034..acac1d6 100644 --- a/assets/js/server-selector.js +++ b/assets/js/server-selector.js @@ -342,6 +342,7 @@ function handleCache(mode, versionString, cacheMode, callback) { path.dirname(versions[0].url); var lastSizes = {}; + var buf = ""; storageLoadingStart(versionString, cacheMode); @@ -349,12 +350,19 @@ function handleCache(mode, versionString, cacheMode, callback) { sock.setEncoding("utf8"); sock.on("data", function (data) { - data.split("\n").forEach(function (sizeString) { - if (sizeString === "") return; + buf += data; - 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); - }); + + end = buf.indexOf("\n"); + } }); });