memory

package
v0.0.0-...-5f226fc Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 4 Imported by: 50

Documentation

Overview

Package memory contains byte size types and manipulation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes converts number of bytes to appropriately sized string.

func ParseString

func ParseString(s string) (int64, error)

ParseString converts string to number of bytes.

Types

type Size

type Size int64

Size implements flag.Value for collecting memory size in bytes.

const (
	B Size = 1 << (10 * iota)
	KiB
	MiB
	GiB
	TiB
	PiB
	EiB

	KB Size = 1e3
	MB Size = 1e6
	GB Size = 1e9
	TB Size = 1e12
	PB Size = 1e15
	EB Size = 1e18
)

base 2 and base 10 sizes.

func (Size) Base10String

func (size Size) Base10String() string

Base10String converts size to a string using base-10 prefixes.

func (Size) Base2String

func (size Size) Base2String() string

Base2String converts size to a string using base-2 prefixes.

func (Size) EB

func (size Size) EB() float64

EB returns size in exabytes.

func (Size) EiB

func (size Size) EiB() float64

EiB returns size in exbibytes.

func (Size) Float64

func (size Size) Float64() float64

Float64 returns bytes size as float64.

func (Size) GB

func (size Size) GB() float64

GB returns size in gigabytes.

func (Size) GiB

func (size Size) GiB() float64

GiB returns size in gibibytes.

func (Size) Int

func (size Size) Int() int

Int returns bytes size as int.

func (Size) Int32

func (size Size) Int32() int32

Int32 returns bytes size as int32.

func (Size) Int64

func (size Size) Int64() int64

Int64 returns bytes size as int64.

func (Size) KB

func (size Size) KB() float64

KB returns size in kilobytes.

func (Size) KiB

func (size Size) KiB() float64

KiB returns size in kibibytes.

func (Size) MB

func (size Size) MB() float64

MB returns size in megabytes.

func (Size) MarshalJSON

func (size Size) MarshalJSON() ([]byte, error)

MarshalJSON returns size as a json string.

func (Size) MarshalText

func (size Size) MarshalText() (string, error)

MarshalText returns size as a string.

func (Size) MiB

func (size Size) MiB() float64

MiB returns size in mebibytes.

func (Size) PB

func (size Size) PB() float64

PB returns size in petabytes.

func (Size) PiB

func (size Size) PiB() float64

PiB returns size in pebibytes.

func (*Size) Set

func (size *Size) Set(s string) error

Set updates value from string.

func (Size) String

func (size Size) String() string

String converts size to a string using base-2 prefixes, unless the number appears to be in base 10.

func (Size) TB

func (size Size) TB() float64

TB returns size in terabytes.

func (Size) TiB

func (size Size) TiB() float64

TiB returns size in tebibytes.

func (Size) Type

func (Size) Type() string

Type implements pflag.Value.

func (*Size) UnmarshalJSON

func (size *Size) UnmarshalJSON(text []byte) error

UnmarshalJSON parses text from a json string.

func (*Size) UnmarshalText

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

UnmarshalText parses text as a string.

type Sizes

type Sizes struct {
	Default []Size
	Custom  []Size
}

Sizes implements flag.Value for collecting memory size.

func (*Sizes) Set

func (sizes *Sizes) Set(s string) error

Set adds values from byte values.

func (Sizes) Sizes

func (sizes Sizes) Sizes() []Size

Sizes returns the loaded values.

func (Sizes) String

func (sizes Sizes) String() string

String converts values to a string.

Jump to

Keyboard shortcuts

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