1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| formatSize(bytes) { const sizes = ["Bytes", "KB", "MB", "GB", "TB"]; if (bytes == 0) { return bytes + " " + sizes[0]; } let flag = ""; if (bytes < 0) { bytes = Math.abs(bytes); flag = "-"; } const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); if (i == 0) { return bytes + " " + sizes[i]; } return flag + (bytes / Math.pow(1024, i)).toFixed(4) + " " + sizes[i]; },
|