MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / formatBytes

Function formatBytes

cmd/gosqlx/cmd/validator.go:367–380  ·  view source on GitHub ↗

formatBytes formats bytes into human-readable format

(bytes int64)

Source from the content-addressed store, hash-verified

365
366// formatBytes formats bytes into human-readable format
367func formatBytes(bytes int64) string {
368 const unit = 1024
369 if bytes < unit {
370 return fmt.Sprintf("%d B", bytes)
371 }
372
373 div, exp := int64(unit), 0
374 for n := bytes / unit; n >= unit; n /= unit {
375 div *= unit
376 exp++
377 }
378
379 return fmt.Sprintf("%.1f %cB", float64(bytes)/float64(div), "KMGTPE"[exp])
380}
381
382// CLI flags structure
383type ValidatorFlags struct {

Callers 2

displayStatsMethod · 0.85

Calls

no outgoing calls

Tested by 1