Skip to content

Instantly share code, notes, and snippets.

@Actine

Actine/stats.js Secret

Created July 8, 2020 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Actine/60aa6a8fe27ee09a2f3e9272d6f91190 to your computer and use it in GitHub Desktop.
Save Actine/60aa6a8fe27ee09a2f3e9272d6f91190 to your computer and use it in GitHub Desktop.
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