Documentation
¶
Index ¶
- type ByteSize
- func (fs ByteSize) Byte() float64
- func (fs ByteSize) ByteInt() int
- func (fs ByteSize) Format(bu ByteSize) string
- func (fs ByteSize) GB() float64
- func (fs ByteSize) GBInt() int
- func (fs ByteSize) KB() float64
- func (fs ByteSize) KBInt() int
- func (fs ByteSize) MB() float64
- func (fs ByteSize) MBInt() int
- func (fs ByteSize) PB() float64
- func (fs ByteSize) PBInt() int
- func (fs ByteSize) String() string
- func (fs ByteSize) TB() float64
- func (fs ByteSize) TBInt() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteSize ¶
type ByteSize int
func Parse ¶
parse a string s in bytes, kilobytes, megabytes, gigabytes, terabytes or petabytes format and converts it into ByteSize, a datatype representing byte sizes. accepts a string s like "10B", "10KB", "10MB", "10GB", "10TB", "10PB" and returns the corresponding ByteSize. returns an error if the format of s is invalid or if an invalid size unit is found.
Example usage:
size, err := Parse("10KB")
if err != nil {
log.Fatal(err)
}
fmt.Println(size)
Output: 10240 // Bytes equivalent of 10KB
func (ByteSize) Format ¶
Format method formats the ByteSize value to a string based on the given byte unit. It iterates over the predefined units until it matches the given unit, then calls formatString to generate the final formatted string. If the unit doesn't match any predefined units, it returns the string representation of the ByteSize itself.