MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / formatBytes

Function formatBytes

internal/cli/cli_helpers.go:297–312  ·  view source on GitHub ↗

formatBytes formats a byte count as a human-readable string (e.g. 1.5 GiB).

(b int64)

Source from the content-addressed store, hash-verified

295
296// formatBytes formats a byte count as a human-readable string (e.g. 1.5 GiB).
297func formatBytes(b int64) string {
298 const unit = 1024
299
300 if b < unit {
301 return fmt.Sprintf("%d B", b)
302 }
303
304 div, exp := int64(unit), 0
305
306 for n := b / unit; n >= unit; n /= unit {
307 div *= unit
308 exp++
309 }
310
311 return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
312}
313
314// formatUptime formats seconds into a human-readable duration string.
315func formatUptime(seconds int64) string {

Callers 6

runStorageListFunction · 0.85
runStorageShowFunction · 0.85
runStorageContentListFunction · 0.85
TestFormatBytesFunction · 0.85
runNodesListFunction · 0.85
runNodesShowFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestFormatBytesFunction · 0.68