(bytes: number)
| 127 | |
| 128 | // 字节转换工具函数 |
| 129 | function formatBytes(bytes: number): string { |
| 130 | if (bytes === 0) return "0 B"; |
| 131 | const k = 1024; |
| 132 | const sizes = ["B", "KB", "MB", "GB", "TB", "PB"]; |
| 133 | const i = Math.floor(Math.log(bytes) / Math.log(k)); |
| 134 | const value = bytes / Math.pow(k, i); |
| 135 | |
| 136 | // 根据值的大小决定小数位数 |
| 137 | let decimals = 2; |
| 138 | if (value >= 100) decimals = 1; |
| 139 | if (value >= 1000) decimals = 0; |
| 140 | |
| 141 | return parseFloat(value.toFixed(decimals)) + " " + sizes[i]; |
| 142 | } |
| 143 | |
| 144 | // 格式化网络速度 |
| 145 | function formatSpeed(bytesPerSecond: number): string { |
no outgoing calls
no test coverage detected