ddstats-server/libs/database/decodeMsgpack.js

22 lines
632 B
JavaScript
Raw Normal View History

2021-11-01 22:20:13 +01:00
import msgpack from '@msgpack/msgpack'
import fs from 'fs'
/**
* This module parses the msgpack provided by DDNet...
* @module db/decodeMsgpack
*/
export default function decodeMsgpack() {
const data = fs.readFileSync(process.env.MSGPACK_PATH ?? 'data/players.msgpack')
const decoded = msgpack.decodeMulti(data, { wrap: true })
const order = ['categories', 'maps', 'totalPoints', 'pointsRanks', 'pointsThisWeek', 'pointsThisMonth', 'teamRankPoints', 'rankPoints', 'serverRanks']
let final = {}
let i = 0
for (const part of decoded) {
final[order[i]] = part
++i
}
return final
}