MCPcopy Create free account
hub / github.com/ZeppelinMC/Zeppelin / FormatSizeUnit

Function FormatSizeUnit

util/unit.go:57–74  ·  view source on GitHub ↗

FormatSizeUnit formats a number of bytes into a human-readable string.

(bytes uint64)

Source from the content-addressed store, hash-verified

55
56// FormatSizeUnit formats a number of bytes into a human-readable string.
57func FormatSizeUnit(bytes uint64) string {
58 if bytes == 0 {
59 return "0 B"
60 }
61
62 var result strings.Builder
63 for i := len(sizeUnitsS) - 1; i >= 0; i-- {
64 unit := sizeUnitsS[i]
65 if bytes >= unit.Factor {
66 value := float64(bytes) / float64(unit.Factor)
67 result.WriteString(fmt.Sprintf("%.2f %s", value, unit.Unit))
68 return result.String()
69 }
70 }
71
72 // This should never be reached since we handle all sizes
73 return "0 B"
74}

Callers 1

mainFunction · 0.92

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected