Skip to content

Instantly share code, notes, and snippets.

@Actine

Actine/stats.js Secret

Created Jul 8, 2020
Embed
What would you like to do?
const dataFile = require(process.argv[2])
const traverse = function(path, node, depth, maxDepth, outputArray) {
if (depth > maxDepth) {
return
}
for (key in node) {
const child = node[key]
const newPath = `${path}/${key}`
const size = JSON.stringify(child).length
if (newPath.endsWith('rows/items') || size < 1024) {
continue
}
console.log(newPath);
const obj = {
path: newPath,
size: size
}
if (newPath.endsWith('cellStorage/rowBuffers')) {
var value = child[Object.keys(child)[0]]
for (var i = 1; i < child.length; i++) {
var temp = child[Object.keys(child)[i]];
if (temp.length > value.length) {
var value = temp
}
}
obj['sampleRow'] = Buffer.from(value, 'base64').toString('utf-8').replace(/[^\x20-\x7E]/g, '?')
outputArray.push(obj)
continue
}
outputArray.push(obj)
if (node instanceof Object) {
traverse(newPath, child, depth + 1, maxDepth, outputArray)
}
}
}
const outputArray = []
traverse('/', dataFile.data, 1, 16, outputArray)
const fs = require('fs')
//fs.writeFileSync('./data-export.json', JSON.stringify({ data: outputArray }, null, 2))
var tsv = ""
outputArray.forEach(i => {
tsv += `\n${i.path}\t${i.size}\t${i.sampleRow || ''}`
})
fs.writeFileSync(process.argv[2] + '-export.tsv', tsv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment