Documentation
¶
Overview ¶
Package prettybytes converts a number of bytes to a human readable string.
It is a faithful port of the npm package "pretty-bytes". By default it uses SI units (base 1000): B, kB, MB, GB, TB, PB, EB, ZB, YB and renders numbers with up to three significant digits (mirroring JavaScript's toPrecision(3)).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrettyBytes ¶
PrettyBytes converts a number of bytes into a human readable string using SI units (base 1000). For example PrettyBytes(1337) returns "1.34 kB".
func PrettyBytesOpts ¶
PrettyBytesOpts converts a number of bytes into a human readable string honouring the supplied Options.
Types ¶
type Options ¶
type Options struct {
// Signed shows a "+" in front of positive numbers (and " " for zero).
Signed bool
// Bits uses bit units (b, kbit, ...) instead of byte units.
Bits bool
// Binary uses base 1024 units (KiB, MiB, ... or kibit, ...).
Binary bool
// MinimumFractionDigits forces a minimum number of fraction digits.
// When nil, no minimum is imposed.
MinimumFractionDigits *int
// MaximumFractionDigits caps the number of fraction digits. When nil the
// default toPrecision(3) behaviour is used.
MaximumFractionDigits *int
}
Options configures how a byte count is rendered.
Click to show internal directories.
Click to hide internal directories.