MCPcopy Index your code
hub / github.com/labstack/echo / format

Function format

middleware/static.go:360–390  ·  view source on GitHub ↗

format formats bytes integer to human readable string. For example, 31323 bytes will return 30.59KB.

(b int64)

Source from the content-addressed store, hash-verified

358// format formats bytes integer to human readable string.
359// For example, 31323 bytes will return 30.59KB.
360func format(b int64) string {
361 multiple := ""
362 value := float64(b)
363
364 switch {
365 case b >= EB:
366 value /= float64(EB)
367 multiple = "EB"
368 case b >= PB:
369 value /= float64(PB)
370 multiple = "PB"
371 case b >= TB:
372 value /= float64(TB)
373 multiple = "TB"
374 case b >= GB:
375 value /= float64(GB)
376 multiple = "GB"
377 case b >= MB:
378 value /= float64(MB)
379 multiple = "MB"
380 case b >= KB:
381 value /= float64(KB)
382 multiple = "KB"
383 case b == 0:
384 return "0"
385 default:
386 return strconv.FormatInt(b, 10) + "B"
387 }
388
389 return fmt.Sprintf("%.2f%s", value, multiple)
390}

Callers 2

TestFormatFunction · 0.85
listDirFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestFormatFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…