FormatFileSize formats file sizes in a human-readable way (e.g., "1.2 KB", "3.4 MB")
(size int64)
| 19 | |
| 20 | // FormatFileSize formats file sizes in a human-readable way (e.g., "1.2 KB", "3.4 MB") |
| 21 | func FormatFileSize(size int64) string { |
| 22 | if size == 0 { |
| 23 | return "0 B" |
| 24 | } |
| 25 | |
| 26 | value, unit := scaleBinaryBytes(size, []string{"KB", "MB", "GB", "TB"}) |
| 27 | if unit == "B" { |
| 28 | return fmt.Sprintf("%d B", size) |
| 29 | } |
| 30 | |
| 31 | return fmt.Sprintf("%.1f %s", value, unit) |
| 32 | } |