MCPcopy
hub / github.com/cli/cli / humanFileSize

Function humanFileSize

pkg/cmd/cache/list/list.go:145–162  ·  view source on GitHub ↗
(s int64)

Source from the content-addressed store, hash-verified

143}
144
145func humanFileSize(s int64) string {
146 if s < 1024 {
147 return fmt.Sprintf("%d B", s)
148 }
149
150 kb := float64(s) / 1024
151 if kb < 1024 {
152 return fmt.Sprintf("%s KiB", floatToString(kb, 2))
153 }
154
155 mb := kb / 1024
156 if mb < 1024 {
157 return fmt.Sprintf("%s MiB", floatToString(mb, 2))
158 }
159
160 gb := mb / 1024
161 return fmt.Sprintf("%s GiB", floatToString(gb, 2))
162}
163
164func floatToString(f float64, p uint8) string {
165 fs := fmt.Sprintf("%#f%0*s", f, p, "")

Callers 2

Test_humanFileSizeFunction · 0.70
listRunFunction · 0.70

Calls 1

floatToStringFunction · 0.70

Tested by 1

Test_humanFileSizeFunction · 0.56