2020-06-26 09:03:45 +02:00
|
|
|
package text
|
|
|
|
|
2020-07-10 02:36:45 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
2020-06-26 09:03:45 +02:00
|
|
|
|
|
|
|
// Human method returns results in human readable format.
|
|
|
|
func Human(size int64) string {
|
|
|
|
floatsize := float32(size)
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-06-26 09:03:45 +02:00
|
|
|
units := [...]string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"}
|
|
|
|
for _, unit := range units {
|
|
|
|
if floatsize < 1024 {
|
|
|
|
return fmt.Sprintf("%.1f %sB", floatsize, unit)
|
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-06-26 09:03:45 +02:00
|
|
|
floatsize /= 1024
|
|
|
|
}
|
2021-08-11 20:13:28 +02:00
|
|
|
|
2020-06-26 09:03:45 +02:00
|
|
|
return fmt.Sprintf("%d%s", size, "B")
|
|
|
|
}
|