bytesize

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2022 License: MIT Imports: 4 Imported by: 8

README

Byte size formatting and parsing.

todo: more robust tests

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.

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 ...

func (Size) AppendFormatSI

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

AppendFormatSI ...

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.

Jump to

Keyboard shortcuts

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