bytesize

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 4 Imported by: 8

README

Byte size formatting and parsing.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidUnit is returned when an invalid IEC/SI is provided.
	ErrInvalidUnit = errors.New("bytesize: invalid unit")

	// ErrInvalidFormat is returned when an invalid size value is provided.
	ErrInvalidFormat = errors.New("bytesize: invalid format")
)

Functions

This section is empty.

Types

type Size

type Size uint64

Size is a casting for uint64 types that provides formatting methods for byte sizes in both IEC and SI units.

const (
	// SI units
	KB Size = 1e3
	MB Size = 1e6
	GB Size = 1e9
	TB Size = 1e12
	PB Size = 1e15
	EB Size = 1e18

	// IEC units
	KiB Size = 1024
	MiB Size = KiB * 1024
	GiB Size = MiB * 1024
	TiB Size = GiB * 1024
	PiB Size = TiB * 1024
	EiB Size = PiB * 1024
)

func ParseSize

func ParseSize(s string) (Size, error)

ParseSize will parse a valid Size from given string. Both IEC and SI units are supported.

func (Size) AppendFormat

func (sz Size) AppendFormat(dst []byte) []byte

AppendFormat defaults to using Size.AppendFormatIEC().

func (Size) AppendFormatIEC

func (sz Size) AppendFormatIEC(dst []byte) []byte

AppendFormatIEC will append IEC formatted size to 'dst'.

func (Size) AppendFormatSI

func (sz Size) AppendFormatSI(dst []byte) []byte

AppendFormatSI will append SI formatted size to 'dst'.

func (*Size) MarshalText added in v1.0.0

func (sz *Size) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler{}.

func (*Size) Set added in v1.0.0

func (sz *Size) Set(in string) error

Set implements flag.Value{}.

func (Size) String

func (sz Size) String() string

String returns a string format of Size, defaults to IEC unit format.

func (Size) StringIEC

func (sz Size) StringIEC() string

StringIEC returns an IEC unit string format of Size.

func (Size) StringSI

func (sz Size) StringSI() string

StringSI returns an SI unit string format of Size.

func (*Size) UnmarshalText added in v1.0.0

func (sz *Size) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler{}.

Jump to

Keyboard shortcuts

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