Documentation
¶
Overview ¶
Package size implements functionality for working with byte sizes.
Index ¶
- Constants
- type Capacity
- func (c Capacity) Bytes() uint64
- func (c Capacity) Exabytes() uint64
- func (c Capacity) Gigabytes() uint64
- func (c Capacity) Kilobytes() uint64
- func (c Capacity) Megabytes() uint64
- func (c Capacity) Petabytes() uint64
- func (c *Capacity) Set(s string) error
- func (c Capacity) String() string
- func (c Capacity) Terabytes() uint64
Constants ¶
View Source
const ( Byte Capacity = 1 Kilobyte = Byte << 10 Megabyte = Kilobyte << 10 Gigabyte = Megabyte << 10 Terabyte = Gigabyte << 10 Petabyte = Terabyte << 10 Exabyte = Petabyte << 10 )
Common capacities.
To count the number of units in a Capacity, divide:
gigabyte := size.Gigabyte fmt.Print(gigabyte/size.Kilobyte) // prints 1048576
To convert an integer number of units to a Capacity, multiply:
gigabytes := 5 fmt.Print(gigabytes*size.Gigabyte) // prints 5G
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Capacity ¶
type Capacity uint64
A Capacity represents a size in bytes.
func ParseCapacity ¶
ParseCapacity parses a capacity string. A capacity string may only contain whole integers and one unit suffix, such as "10G" or "5T". Valid capacity units are "K", "M", "G", "T", "P", "E".
Click to show internal directories.
Click to hide internal directories.