(bytes, decimals = 2)
| 19 | } |
| 20 | |
| 21 | function formatBytes(bytes, decimals = 2) { |
| 22 | if (bytes === 0) return '0 Bytes'; |
| 23 | |
| 24 | const k = 1024; |
| 25 | const dm = decimals < 0 ? 0 : decimals; |
| 26 | const sizes = ['bytes', 'kb', 'mb', 'gb', 'tb', 'pb']; |
| 27 | |
| 28 | const i = Math.floor(Math.log(bytes) / Math.log(k)); |
| 29 | const type = sizes[i] |
| 30 | const space = type === 'bytes' ? ' ' : '' |
| 31 | return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + space + type; |
| 32 | } |
| 33 | |
| 34 | async function getSizeInfo(code, filename) { |
| 35 | const raw = code.length < 5000 |