MCPcopy Index your code
hub / github.com/cloudfoundry/cli / ByteSize

Function ByteSize

cf/formatters/bytes.go:21–47  ·  view source on GitHub ↗
(bytes int64)

Source from the content-addressed store, hash-verified

19)
20
21func ByteSize(bytes int64) string {
22 unit := ""
23 value := float32(bytes)
24
25 switch {
26 case bytes >= TERABYTE:
27 unit = "T"
28 value = value / TERABYTE
29 case bytes >= GIGABYTE:
30 unit = "G"
31 value = value / GIGABYTE
32 case bytes >= MEGABYTE:
33 unit = "M"
34 value = value / MEGABYTE
35 case bytes >= KILOBYTE:
36 unit = "K"
37 value = value / KILOBYTE
38 case bytes == 0:
39 return "0"
40 case bytes < KILOBYTE:
41 unit = "B"
42 }
43
44 stringValue := fmt.Sprintf("%.1f", value)
45 stringValue = strings.TrimSuffix(stringValue, ".0")
46 return fmt.Sprintf("%s%s", stringValue, unit)
47}
48
49func ToMegabytes(s string) (int64, error) {
50 parts := bytesPattern.FindStringSubmatch(strings.TrimSpace(s))

Callers 12

ExecuteMethod · 0.92
ExecuteMethod · 0.92
ExecuteMethod · 0.92
ExecuteMethod · 0.92
uploadAppMethod · 0.92
ExecuteMethod · 0.92
ExecuteMethod · 0.92
ShowAppMethod · 0.92
printProgressMethod · 0.92
FormattedMemoryLimitMethod · 0.92
bytes_test.goFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected