bytesize

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IECSize

type IECSize uint64

IECSize represents IEC (base-2) byte sizes (1 KiB = 2^10 bytes).

const (
	Byte IECSize = 1
	KiB  IECSize = 1 << (iota * 10) // 2^10 = 1024 (Kibibyte)
	MiB                             // 2^20 = 1048576 (Mebibyte)
	GiB                             // 2^30 = 1073741824 (Gibibyte)
	TiB                             // 2^40 = 1099511627776 (Tebibyte)
	PiB                             // 2^50 = 1125899906842624 (Pebibyte)
	EiB                             // 2^60 = 1152921504606846976 (Exbibyte)

)

IEC (base-2) byte size constants.

func (IECSize) Bytes

func (s IECSize) Bytes() uint64

Bytes returns the raw byte count.

func (IECSize) MarshalSetting

func (s IECSize) MarshalSetting() ([]byte, error)

func (IECSize) String

func (s IECSize) String() string

String converts an IECSize to a human-readable string (base 1024).

func (*IECSize) UnmarshalSetting

func (s *IECSize) UnmarshalSetting(data []byte) error

type SISize

type SISize uint64

SISize represents SI (base-10) byte sizes (1 KB = 10^3 bytes).

const (
	ByteSI SISize = 1
	KB     SISize = 1000 * ByteSI // 10^3 = 1000 (Kilobyte)
	MB     SISize = 1000 * KB     // 10^6 = 1000000 (Megabyte)
	GB     SISize = 1000 * MB     // 10^9 = 1000000000 (Gigabyte)
	TB     SISize = 1000 * GB     // 10^12 = 1000000000000 (Terabyte)
	PB     SISize = 1000 * TB     // 10^15 = 1000000000000000 (Petabyte)
	EB     SISize = 1000 * PB     // 10^18 = 1000000000000000000 (Exabyte)

)

SI (base-10) byte size constants.

func (SISize) Bytes

func (s SISize) Bytes() uint64

Bytes returns the raw byte count.

func (SISize) MarshalSetting

func (s SISize) MarshalSetting() ([]byte, error)

func (SISize) String

func (s SISize) String() string

String converts an SISize to a human-readable string (base 1000).

func (*SISize) UnmarshalSetting

func (s *SISize) UnmarshalSetting(data []byte) error

type Size

type Size interface {
	String() string
	Bytes() uint64
}

Size is an interface for byte sizes, providing human-readable string and raw bytes.

func Parse

func Parse(s string) (Size, error)

Parse parses a string like "1.5 GB" or "1024 MiB" into a Size (SISize or IECSize).

Jump to

Keyboard shortcuts

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