Skip to content

Instantly share code, notes, and snippets.

@rozek
Last active January 14, 2020 05:51
Show Gist options
  • Save rozek/aedc2eda3c0016045289cb1cc8c90184 to your computer and use it in GitHub Desktop.
Save rozek/aedc2eda3c0016045289cb1cc8c90184 to your computer and use it in GitHub Desktop.
Bangle.js: list all "logical" files on the internal file system
const Storage = require('Storage');
print('compacting internal Storage...');
Storage.compact();
print('internal Storage report:');
print('-',Storage.getFree(),'bytes free');
print('- list of stored files');
let FileList = Storage.list();
let segmentedFileSet = Object.create(null);
for (let i = 0, l = FileList.length; i < l; i++) {
let FileName = FileList[i];
if (/\x01$/.test(FileName)) {
segmentedFileSet[FileName.replace(/.$/,'')] = true;
}
}
for (let i = FileList.length-1; i >= 0; i--) {
let FileName = FileList[i];
if (FileName.slice(0,FileName.length-1) in segmentedFileSet) {
FileList.splice(i,1);
}
}
for (let FileName in segmentedFileSet) {
FileList.push(FileName);
}
for (let i = 0, l = FileList.length; i < l; i++) {
print(' -',FileList[i].replace(/[\x00-\x1F\x7F-\x9F]/g, function (Match) {
let CharCode = Match.charCodeAt(0);
return '\\x' + (CharCode < 16 ? '0' : '') + CharCode.toString(16);
}));
}
print('done');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment