(bytes: number)
| 10 | * @returns 格式化后字节大小 |
| 11 | */ |
| 12 | export const bytesToSize = (bytes: number) => { |
| 13 | if (typeof bytes !== 'number') { |
| 14 | return '-'; |
| 15 | } |
| 16 | if (bytes === 0) return '0 B'; |
| 17 | const k = 1024; |
| 18 | const i = Math.floor(Math.log(bytes) / Math.log(k)); |
| 19 | return `${(bytes / (k ** i)).toPrecision(3)} ${sizes[i]}`; |
| 20 | }; |