| 299 | } |
| 300 | |
| 301 | String formatBytes(uint64_t bytes) { |
| 302 | const char *units[] = {"B", "KB", "MB", "GB", "TB"}; |
| 303 | int unitIndex = 0; |
| 304 | float size = bytes; |
| 305 | |
| 306 | while (size >= 1024.0 && unitIndex < 4) { |
| 307 | size /= 1024.0; |
| 308 | unitIndex++; |
| 309 | } |
| 310 | |
| 311 | if (unitIndex == 0) { |
| 312 | return String(bytes) + " " + units[unitIndex]; |
| 313 | } else { |
| 314 | return String(size, 2) + " " + units[unitIndex]; |
| 315 | } |
| 316 | } |