inline prettyBytes

This commit is contained in:
Girish Ramakrishnan
2022-04-15 09:18:07 -05:00
parent 555f914537
commit bdc9a0cbe3
2 changed files with 10 additions and 16 deletions

View File

@@ -40,7 +40,6 @@ const assert = require('assert'),
mounts = require('../mounts.js'),
path = require('path'),
paths = require('../paths.js'),
prettyBytes = require('../pretty-bytes.js'),
readdirp = require('readdirp'),
safe = require('safetydance'),
shell = require('../shell.js');
@@ -62,6 +61,16 @@ function getRootPath(apiConfig) {
}
}
// binary units (non SI) 1024 based
function prettyBytes(size) {
assert.strictEqual(typeof size, 'number');
if (!size) return 0;
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];
}
// the du call in the function below requires root
async function checkPreconditions(apiConfig, dataLayout) {
assert.strictEqual(typeof apiConfig, 'object');