Fixup prettyBytes

This commit is contained in:
Girish Ramakrishnan
2022-04-15 17:56:24 -05:00
parent 26f9635a38
commit 64a2493ca2

View File

@@ -62,13 +62,13 @@ function getRootPath(apiConfig) {
}
// binary units (non SI) 1024 based
function prettyBytes(size) {
assert.strictEqual(typeof size, 'number');
function prettyBytes(bytes) {
assert.strictEqual(typeof bytes, 'number');
if (!size) return 0;
const i = Math.floor(Math.log(bytes) / Math.log(1024)),
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(size) / Math.log(1024));
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
return (bytes / Math.pow(1024, i)).toFixed(2) * 1 + '' + sizes[i];
}
// the du call in the function below requires root