diff options
| author | 2026-03-08 14:15:38 +0800 | |
|---|---|---|
| committer | 2026-03-08 14:15:38 +0800 | |
| commit | c75a034d25ca87f3d209a8e82c743b8a7e96573b (patch) | |
| tree | d8cd5befb9d812ab622dcce094c9d30797d6d861 /internal/progress/humanize.go | |
| parent | *: BestEffortFprintf as linter wants (diff) | |
| signature | No signature | |
internal/progress: Add progress meter
Diffstat (limited to 'internal/progress/humanize.go')
| -rw-r--r-- | internal/progress/humanize.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/progress/humanize.go b/internal/progress/humanize.go new file mode 100644 index 00000000..8363d6b1 --- /dev/null +++ b/internal/progress/humanize.go @@ -0,0 +1,21 @@ +package progress + +import "fmt" + +func humanizeBytes(n uint64) string { + const unit = 1024 + if n < unit { + return fmt.Sprintf("%d B", n) + } + + value := float64(n) + units := []string{"KiB", "MiB", "GiB", "TiB", "PiB"} + for i := 0; i < len(units); i++ { + value /= unit + if value < unit || i == len(units)-1 { + return fmt.Sprintf("%.2f %s", value, units[i]) + } + } + + return fmt.Sprintf("%d B", n) +} |
