Documentation ¶
Overview ¶
Package bytesize provides a function for formatting and parsing quantities of data as human-readable values such as 1MB or 2.2GB.
Index ¶
Constants ¶
const ( KB float64 = 1000 MB = 1000 * KB GB = 1000 * MB TB = 1000 * GB PB = 1000 * TB EB = 1000 * PB ZB = 1000 * EB YB = 1000 * ZB )
SI (base 10) units See http://physics.nist.gov/cuu/Units/prefixes.html
const ( KiB float64 = 1 << (10 * iota) MiB GiB TiB PiB EiB ZiB YiB )
IEC (base 2) units See http://physics.nist.gov/cuu/Units/binary.html and https://en.wikipedia.org/wiki/Binary_prefix
Variables ¶
This section is empty.
Functions ¶
func FormatBytes ¶
FormatBytes formats the specified number of bytes in human-readable format, in either base 2 (IEC) or base 10 (SI) units as specified by the base parameter, with the specified number of digits of precision.
e.g.
FormatBytes(1024*1024, 2, 2) => "1.00MiB" FormatBytes(2000000000, 10, 2) => "2.00GB"
If an invalid base or precision is given, a Sprintf-style error string is returned, starting %! followed by an error code in parentheses.
func ParseBytes ¶
ParseBytes parses a human-readable quantity of bytes, and returns the raw number of bytes as an int64. If the value is too large for an int64, an error value is returned.
Whitespace is allowed between the number and the units. The 'B' for bytes is required to be upper case; 'b' in lower case would be bits.
func ParseBytesFloat ¶
ParseBytesFloat parses a human-readable quantity of bytes, and returns the raw number of bytes as a float64.
Whitespace is allowed between the number and the units. The 'B' for bytes is required to be upper case; 'b' in lower case would be bits.
Types ¶
This section is empty.