MCPcopy Create free account
hub / github.com/github/gh-aw / scaleBinaryBytes

Function scaleBinaryBytes

pkg/console/format.go:5–18  ·  view source on GitHub ↗
(size int64, units []string)

Source from the content-addressed store, hash-verified

3import "fmt"
4
5func scaleBinaryBytes(size int64, units []string) (float64, string) {
6 const unit = 1024
7 if size < unit {
8 return float64(size), "B"
9 }
10
11 div, exp := int64(unit), 0
12 for n := size / unit; n >= unit && exp < len(units)-1; n /= unit {
13 div *= unit
14 exp++
15 }
16
17 return float64(size) / float64(div), units[exp]
18}
19
20// FormatFileSize formats file sizes in a human-readable way (e.g., "1.2 KB", "3.4 MB")
21func FormatFileSize(size int64) string {

Callers 2

formatBytesFunction · 0.85
FormatFileSizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected