MCPcopy Create free account
hub / github.com/cli/cli / humanFileSize

Function humanFileSize

pkg/cmd/release/view/view.go:202–219  ·  view source on GitHub ↗
(s int64)

Source from the content-addressed store, hash-verified

200}
201
202func humanFileSize(s int64) string {
203 if s < 1024 {
204 return fmt.Sprintf("%d B", s)
205 }
206
207 kb := float64(s) / 1024
208 if kb < 1024 {
209 return fmt.Sprintf("%s KiB", floatToString(kb, 2))
210 }
211
212 mb := kb / 1024
213 if mb < 1024 {
214 return fmt.Sprintf("%s MiB", floatToString(mb, 2))
215 }
216
217 gb := mb / 1024
218 return fmt.Sprintf("%s GiB", floatToString(gb, 2))
219}
220
221// render float to fixed precision using truncation instead of rounding
222func floatToString(f float64, p uint8) string {

Callers 2

Test_humanFileSizeFunction · 0.70
renderReleaseTTYFunction · 0.70

Calls 1

floatToStringFunction · 0.70

Tested by 1

Test_humanFileSizeFunction · 0.56