Add HumanBytes to print a byte count in a readable form #11
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Any program that reports on files, downloads or memory ends up printing a byte
count, and a bare number of bytes is hard to read at a glance while the loop
that turns it into "1.5 MiB" is fiddly enough to be worth writing once. The repo
already prints a duration in a readable form with
TimeDiffHuman, so the sametreatment for sizes fits alongside it.
Definition of done:
HumanBytes(bytes uint64) stringreturns a short stringusing powers of 1024, with whole bytes below 1024 and one digit after the
decimal point above that. It has a doc comment and table-driven tests covering
zero, a value just below the first threshold, each unit up to exabytes, a value
that would otherwise round up into the next unit, and the largest value a
uint64 can hold.
Model: opus-5