Documentation
¶
Overview ¶
Package humanbytes converts bytes to human-readable strings with ls -lh semantics. For bytes >= 1 KiB/kB, human-readable strings are in the form "X.Y <suffix>" where X and Y are single digits, or "Z <suffix>" where Z is two or three digits.
All sizes are aggressively rounded up:
- 1025 rounds to 1.1 K
- 9.9 * 1024**2 + 1 rounds to 10 M
Base-2 and Base-10 are supported, including modern Base-2 suffixes.
Additional Info
ls -lh has special, irregular semantics I couldn’t find all implemented together in the same library!
- Use no decimal pt or unit suffix for values under 1024 bytes: 0 or 897
- Use one decimal if the integer part is a single digit: 1.0 K or 9.9 M
- Use no decimal if the integer part is more than one digit: 10 K or 582 M
- Aggressively round up: 999 M + 1 byte rounds up to 1 G
.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.