Last active
April 25, 2021 05:26
-
-
Save mendes5/8124ef0ded1b6572547119703cb71087 to your computer and use it in GitHub Desktop.
Parses the data from NCDU dump file https://dev.yorhel.nl/ncdu/jsonfmt, the folder sizes are probably wrong tho....
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var computeDirSize = (list) => | |
| list.reduce((prev, curr) => { | |
| if (curr.type === "FOLDER") { | |
| return computeDirSize(curr.children) + prev; | |
| } else { | |
| return curr.value + prev; | |
| } | |
| }, 0) || 0; | |
| var readFile = file => ({ | |
| type: "FILE", | |
| name: file.name, | |
| value: file.asize || 1, | |
| }); | |
| var readFolder = ([folderInfo, ...folderItems]) => { | |
| const children = folderItems.map(recursiveRead).sort((a, b) => a.value - b.value); | |
| return { | |
| type: "FOLDER", | |
| name: folderInfo.name, | |
| value: computeDirSize(children) || 1, | |
| children, | |
| }; | |
| }; | |
| var recursiveRead = (items) => { | |
| if (Array.isArray(items)) { | |
| return readFolder(items); | |
| } else { | |
| return readFile(items); | |
| } | |
| }; | |
| l=recursiveRead(z) | |
| fs.writeFileSync('./parsed.json', JSON.stringify(l)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment