| 200 | } |
| 201 | |
| 202 | func humanFileSize(s int64) string { |
| 203 | if s < 1024 { |
| 204 | return fmt.Sprintf("%d B", s) |
| 205 | } |
| 206 | |
| 207 | kb := float64(s) / 1024 |
| 208 | if kb < 1024 { |
| 209 | return fmt.Sprintf("%s KiB", floatToString(kb, 2)) |
| 210 | } |
| 211 | |
| 212 | mb := kb / 1024 |
| 213 | if mb < 1024 { |
| 214 | return fmt.Sprintf("%s MiB", floatToString(mb, 2)) |
| 215 | } |
| 216 | |
| 217 | gb := mb / 1024 |
| 218 | return fmt.Sprintf("%s GiB", floatToString(gb, 2)) |
| 219 | } |
| 220 | |
| 221 | // render float to fixed precision using truncation instead of rounding |
| 222 | func floatToString(f float64, p uint8) string { |