MCPcopy Index your code
hub / github.com/codechenx/FastTableViewer / formatBytes

Function formatBytes

buffer.go:213–225  ·  view source on GitHub ↗

formatBytes formats bytes into human-readable format

(bytes int64)

Source from the content-addressed store, hash-verified

211
212// formatBytes formats bytes into human-readable format
213func formatBytes(bytes int64) string {
214 const unit = 1024
215 if bytes < unit {
216 return strconv.FormatInt(bytes, 10) + " B"
217 }
218 div, exp := int64(unit), 0
219 for n := bytes / unit; n >= unit; n /= unit {
220 div *= unit
221 exp++
222 }
223 units := []string{"KB", "MB", "GB", "TB"}
224 return strconv.FormatFloat(float64(bytes)/float64(div), 'f', 2, 64) + " " + units[exp]
225}
226
227// resizeColUnsafe adjusts the number of columns (must be called with lock held)
228// Fills missing columns with "NaN"

Callers 5

TestFormatBytesFunction · 0.85
contAppendSliMethod · 0.85
getMemoryStatsMethod · 0.85

Calls

no outgoing calls

Tested by 3

TestFormatBytesFunction · 0.68