convert

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2024 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const ExponentialFold = 2

ExponentialFold defines the value to fold back to the previous exponent for better display of a small value.

View Source
const IECBase = 1024

IECBase is the exponential base for IEC units.

View Source
const SIBase = 1000

SIBase is the exponential base for SI units.

Variables

View Source
var ByteIECUnits = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB"}

ByteIECUnits lists known units we can convert to based on uint64.

See https://en.wikipedia.org/wiki/Byte#Unit_symbol

View Source
var ByteSIUnits = []string{"B", "KB", "MB", "GB", "TB", "PB"}

ByteSIUnits lists known units we can convert to based on uint64.

See https://en.wikipedia.org/wiki/Byte#Unit_symbol

Functions

This section is empty.

Types

type ByteAny added in v0.3.0

type ByteAny interface {
	HumanReadable() string
	Bytes() uint64
	fmt.Stringer
}

func ParseBytes

func ParseBytes(value string) (ByteAny, error)

ParseBytes parses a strings and returns the proper ByteAny implementation based on the unit specified.

When a plain value or B unit is used, ByteIEC is returned.

type BytesIEC added in v0.3.0

type BytesIEC uint64

BytesIEC is the IEC (1024) unit implementation of byte conversion.

func (BytesIEC) Bytes added in v0.3.0

func (b BytesIEC) Bytes() uint64

Bytes returns the value as uint64.

func (BytesIEC) HumanReadable added in v0.3.0

func (b BytesIEC) HumanReadable() string

HumanReadable returns the biggest sensible unit for the byte value with 2 decimal precision.

When value is smaller than 2 render it with a lower scale.

func (BytesIEC) String added in v0.3.0

func (b BytesIEC) String() string

type BytesSI added in v0.3.0

type BytesSI uint64

BytesSI is the SI (1000) unit implementation of byte conversion.

func (BytesSI) Bytes added in v0.3.0

func (b BytesSI) Bytes() uint64

Bytes returns the value as uint64.

func (BytesSI) HumanReadable added in v0.3.0

func (b BytesSI) HumanReadable() string

HumanReadable returns the biggest sensible unit for the byte value with 2 decimal precision.

When value is smaller than 2 render it with a lower scale.

func (BytesSI) String added in v0.3.0

func (b BytesSI) String() string

String returns a text representation of the current value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL