Documentation ¶
Overview ¶
Package bytesize formats data sizes as strings.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRange indicates that the byte size is too large to fit in a uint64. ErrRange = errors.New("byte size out of range") )
Functions ¶
func Format ¶
Format formats a data size for humans. The size is rounded to three significant digits, but never more than integer accuracy, and printed with SI prefixes, with the unit B for bytes.
For example, 1000 is formatted as "1.00 kB".
This uses unbiased, round-to-even rounding just like the standard library does (math.Round, strconv.FormatFloat). So 1005 is "1.00 kB", and 1015 is "1.02 kB".
func Parse ¶ added in v1.1.0
Parse parses a string as a byte size, which may contain units and may use a decimal point. If the result would overflow a uint64, returns a ParseError with an ErrRange inside. Results are rounded to even, although results for binary prefixes may not be exactly rounded. The units are the standard SI units as well as their binary counterparts, optionally followed by "b". ASCII space characters may appear between the number and the units.
Parse("1") = 1 Parse("555k") = 555000 Parse("15 EiB") = 17293822569102704640 Parse("1.5 mb") = 1500000 Parse("2gi") = 2147483648 Parse("0.001 zb") = 1000000000000000000
Types ¶
type ParseError ¶ added in v1.1.0
An ParseError is an error parsing a byte size.
func (*ParseError) Error ¶ added in v1.1.0
func (e *ParseError) Error() string