From a5053b17e51551d7c9b23b05c207256017723017 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Thu, 22 Apr 2021 15:00:54 -0700 Subject: [PATCH] Fixed agent log parsing bug --- agents/modules_meshcore/util-agentlog.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/agents/modules_meshcore/util-agentlog.js b/agents/modules_meshcore/util-agentlog.js index a192eb1e..2c0472b9 100644 --- a/agents/modules_meshcore/util-agentlog.js +++ b/agents/modules_meshcore/util-agentlog.js @@ -109,10 +109,24 @@ function parseLine(entry) function readLog_data(buffer) { - var lines = buffer.toString().split('\n'); - while(lines.length > 0) + var lines = buffer.toString(); + if (this.buffered != null) { lines = this.buffered + lines; } + lines = lines.split('\n'); + var i; + + for (i = 0; i < (lines.length - 1) ; ++i) { - parseLine.call(this, lines.shift()); + parseLine.call(this, lines[i]); + } + + if (lines.length == 1) + { + parseLine.call(this, lines[0]); + this.buffered = null; + } + else + { + this.buffered = lines[lines.length - 1]; } } @@ -122,9 +136,11 @@ function readLogEx(path) try { var s = require('fs').createReadStream(path); + s.buffered = null; s.results = ret; s.on('data', readLog_data); s.resume(); + if (s.buffered != null) { readLog_data.call(s, s.buffered); s.buffered = null; } s.removeAllListeners('data'); s = null; }