GetByteSizeString takes a number of bytes and precision and returns a human representation of the amount of data.
(input int64, precision uint)
| 158 | // GetByteSizeString takes a number of bytes and precision and returns a |
| 159 | // human representation of the amount of data. |
| 160 | func GetByteSizeString(input int64, precision uint) string { |
| 161 | if input < 1000 { |
| 162 | return fmt.Sprintf("%dB", input) |
| 163 | } |
| 164 | |
| 165 | value := float64(input) |
| 166 | |
| 167 | for _, unit := range []string{"kB", "MB", "GB", "TB", "PB", "EB"} { |
| 168 | value = value / 1000 |
| 169 | if value < 1000 { |
| 170 | return fmt.Sprintf("%.*f%s", precision, value, unit) |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | return fmt.Sprintf("%.*fEB", precision, value) |
| 175 | } |
| 176 | |
| 177 | // GetByteSizeStringIEC takes a number of bytes and precision and returns a |
| 178 | // human representation of the amount of data using IEC units. |
no outgoing calls
no test coverage detected
searching dependent graphs…