Documentation ¶
Overview ¶
Example ¶
b := Bytesize(10000) fmt.Printf("%g bytes is: %g KB and %g MB\n", b, b.Kilobytes(), b.Megabytes())
Output: 10000 bytes is: 10 KB and 0.01 MB
Index ¶
- type Bytesize
- func (b Bytesize) Bytes() float64
- func (b Bytesize) Exabytes() float64
- func (b Bytesize) Exbibytes() float64
- func (b Bytesize) Format(layout string) string
- func (b Bytesize) Gibibytes() float64
- func (b Bytesize) Gigabytes() float64
- func (b Bytesize) Kibibytes() float64
- func (b Bytesize) Kilobytes() float64
- func (b Bytesize) Mebibytes() float64
- func (b Bytesize) Megabytes() float64
- func (b Bytesize) Pebibytes() float64
- func (b Bytesize) Petabytes() float64
- func (b Bytesize) Tebibytes() float64
- func (b Bytesize) Terabytes() float64
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bytesize ¶
type Bytesize float64
A Bytesize represents a single byte as a float64
const ( B Bytesize = 1 KB Bytesize = 1000 * B MB Bytesize = 1000 * KB GB Bytesize = 1000 * MB TB Bytesize = 1000 * GB PB Bytesize = 1000 * TB EB Bytesize = 1000 * PB KiB Bytesize = 1024 * B MiB Bytesize = 1024 * KiB GiB Bytesize = 1024 * MiB TiB Bytesize = 1024 * GiB PiB Bytesize = 1024 * TiB EiB Bytesize = 1024 * PiB )
bytes sizes generally used for computer storage and memory
func (Bytesize) Format ¶
Format returns a textual representation of the Bytesize value formatted according to layout, which defines the format by specifying an abbreviation. Abbreviations are not case-sensitive.
Valid abbreviations are as follows:
B (Bytesizes) KB (Kilobytes) MB (Megabytes) GB (Gigabytes) TB (Terabytes) PB (Petabytes) EB (Exabytes) KiB (Kibibytes) MiB (Mebibytes) GiB (Gibibytes) TiB (Tebibtyes) PiB (Pebibytes) EiB (Exbibyte)
Example ¶
b := Bytesize(100000) fmt.Println(b.Format("b")) fmt.Println(b.Format("kb")) fmt.Println(b.Format("gb")) fmt.Println(b.Format("tb")) fmt.Println(b.Format("pb")) fmt.Println(b.Format("eb")) fmt.Println(b.Format("kib")) fmt.Println(b.Format("gib")) fmt.Println(b.Format("tib")) fmt.Println(b.Format("pib")) fmt.Println(b.Format("eib"))
Output: 100000B 100KB 0.0001GB 1e-07TB 1e-10PB 1e-13EB 97.65625KiB 9.313225746154785e-05GiB 9.094947017729282e-08TiB 8.881784197001252e-11PiB 8.673617379884035e-14EiB
Click to show internal directories.
Click to hide internal directories.