datasizes

package
v0.254.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const (
	KiloByte = 1000                      // kB
	KibiByte = 1024                      // KiB
	MegaByte = 1000 * 1000               // MB
	MebiByte = 1024 * 1024               // MiB
	GigaByte = 1000 * 1000 * 1000        // GB
	GibiByte = 1024 * 1024 * 1024        // GiB
	TeraByte = 1000 * 1000 * 1000 * 1000 // TB
	TebiByte = 1024 * 1024 * 1024 * 1024 // TiB

	// shorthands
	KiB = KibiByte
	MB  = MegaByte
	MiB = MebiByte
	GB  = GigaByte
	GiB = GibiByte
	TiB = TebiByte
)

Variables

This section is empty.

Functions

func Parse

func Parse(size string) (uint64, error)

Parse converts a size specified as a string in KB/KiB/MB/etc. to a number of bytes represented by uint64. Floats are allowed for units other than bytes (e.g., "1.5 GiB" converts to bytes). For bytes (no unit), fractional values like "1.5" or "123.45 B" error out.

Types

type Size

type Size uint64

Size is a wrapper around uint64 with support for reading from string yaml/toml, so {"size": 123}, {"size": "1234"}, {"size": "1 GiB"} are all supported

func (Size) Uint64

func (si Size) Uint64() uint64

Uint64 returns the size as uint64. This is a convenience functions, it is strictly equivalent to uint64(Size(1))

func (*Size) UnmarshalJSON

func (si *Size) UnmarshalJSON(data []byte) error

func (*Size) UnmarshalTOML

func (si *Size) UnmarshalTOML(data interface{}) error

func (*Size) UnmarshalYAML added in v0.203.0

func (si *Size) UnmarshalYAML(unmarshal func(any) error) error

Jump to

Keyboard shortcuts

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