-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (29 loc) · 958 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var fs = require("fs");
var JSONStream = require('JSONStream');
var es = require('event-stream');
var jsondiffpatch = require("jsondiffpatch");
const writeFile = () => {
console.log("attempting to write file");
fs.writeFile("diffLog.json", JSON.stringify(diffedLogs), (err) => console.log(err));
}
var getStream = function () {
var jsonData = 'match-status.json',
stream = fs.createReadStream(jsonData, { encoding: 'utf8' }).on("end", writeFile),
parser = JSONStream.parse('*');
return stream.pipe(parser);
};
const diffedLogs = [];
let previousTick;
getStream()
.pipe(es.mapSync(function (data) {
if(data.World.CurrentTick === 0){
diffedLogs.push(data);
previousTick = data;
return;
} else {
var delta = jsondiffpatch.diff(previousTick, data);
diffedLogs.push(delta);
previousTick = data;
}
console.log("Current Tick: ", data.World.CurrentTick);
}));