(bytes int64)
| 6 | ) |
| 7 | |
| 8 | func ConvertBytesToString(bytes int64) string { |
| 9 | sizes := []string{"Bytes", "KB", "MB", "GB", "TB"} |
| 10 | var bytesFloat float64 = float64(bytes) |
| 11 | |
| 12 | if bytes == 0 { |
| 13 | return "0 Bytes" |
| 14 | } |
| 15 | |
| 16 | var i int = int(math.Floor(math.Log(bytesFloat) / math.Log(1024))) |
| 17 | |
| 18 | if i == 0 { |
| 19 | return fmt.Sprintf("%d %s", bytes, sizes[i]) |
| 20 | } |
| 21 | |
| 22 | return fmt.Sprintf("%.1f %s", (bytesFloat / math.Pow(1024, float64(i))), sizes[i]) |
| 23 | } |
no outgoing calls
no test coverage detected