(size int64, units []string)
| 3 | import "fmt" |
| 4 | |
| 5 | func scaleBinaryBytes(size int64, units []string) (float64, string) { |
| 6 | const unit = 1024 |
| 7 | if size < unit { |
| 8 | return float64(size), "B" |
| 9 | } |
| 10 | |
| 11 | div, exp := int64(unit), 0 |
| 12 | for n := size / unit; n >= unit && exp < len(units)-1; n /= unit { |
| 13 | div *= unit |
| 14 | exp++ |
| 15 | } |
| 16 | |
| 17 | return float64(size) / float64(div), units[exp] |
| 18 | } |
| 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 { |
no outgoing calls
no test coverage detected