MCPcopy
hub / github.com/git-lfs/git-lfs / FormatBytes

Function FormatBytes

tools/humanize/humanize.go:102–115  ·  view source on GitHub ↗

FormatBytes outputs the given number of bytes "s" as a human-readable string, rounding to the nearest half within .01.

(s uint64)

Source from the content-addressed store, hash-verified

100// FormatBytes outputs the given number of bytes "s" as a human-readable string,
101// rounding to the nearest half within .01.
102func FormatBytes(s uint64) string {
103 var e float64
104 if s == 0 {
105 e = 0
106 } else {
107 e = math.Floor(log(float64(s), 1000))
108 }
109
110 unit := uint64(math.Pow(1000, e))
111 suffix := sizes[int(e)]
112
113 return fmt.Sprintf("%s %s",
114 FormatBytesUnit(s, unit), suffix)
115}
116
117// FormatBytesUnit outputs the given number of bytes "s" as a quantity of the
118// given units "u" to the nearest half within .01.

Callers 7

AssertMethod · 0.92
downloadFileMethod · 0.92
lsFilesCommandFunction · 0.92
pruneFunction · 0.92
logVerboseOutputFunction · 0.92
PrintMethod · 0.92
strMethod · 0.92

Calls 2

FormatBytesUnitFunction · 0.85
logFunction · 0.70

Tested by 1

AssertMethod · 0.74