refactor: improved logging on pruning

This commit is contained in:
2023-02-19 10:28:18 +01:00
parent 5739758c3a
commit d62c4e3400
3 changed files with 33 additions and 7 deletions

View File

@ -1,6 +1,7 @@
package formatter
import (
"fmt"
"os"
"strings"
"time"
@ -70,3 +71,21 @@ func StripTagMeta(image string) string {
return image
}
// ByteCountSI presents a human friendly representation of a byte count. See
// https://yourbasic.org/golang/formatting-byte-size-to-human-readable-format.
func ByteCountSI(b uint64) string {
const unit = 1000
if b < unit {
return fmt.Sprintf("%d B", b)
}
div, exp := uint64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %cB", float64(b)/float64(div), "kMGTPE"[exp])
}