sdk: byte formatting

This commit is contained in:
mappu 2017-10-08 15:07:04 +13:00
parent 97b00b7143
commit 030c270e77
1 changed files with 9 additions and 2 deletions

View File

@ -5,8 +5,15 @@ var contented = (function ($, currentScriptPath) {
var baseURL = currentScriptPath.replace('sdk.js', '');
var formatBytes = function(bytes) {
// FIXME
return Math.floor(bytes / (1024 * 1024)) + " MiB";
if (bytes < 1024) {
return bytes + " B";
} else if (bytes < (1024*1024)) {
return (bytes / 1024).toFixed(1) + " KiB";
} else if (bytes < (1024*1024*1024)) {
return (bytes / (1024*1024)).toFixed(1) + " MiB";
} else {
return (bytes / (1024*1024*1024)).toFixed(1) + " GiB";
}
};
/**