datasize

package
v0.0.67 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0, NCSA Imports: 7 Imported by: 6

Documentation

Overview

Package datasize implements a type representing data sizes in bytes.

Index

Constants

View Source
const (
	Kilobyte Size = 1000 * Byte
	Megabyte      = 1000 * Kilobyte
	Gigabyte      = 1000 * Megabyte
	Terabyte      = 1000 * Gigabyte
	Petabyte      = 1000 * Terabyte
)

Common decimal data sizes

View Source
const (
	Byte     Size = 1
	Kibibyte      = 1024 * Byte
	Mebibyte      = 1024 * Kibibyte
	Gibibyte      = 1024 * Mebibyte
	Tebibyte      = 1024 * Gibibyte
	Pebibyte      = 1024 * Tebibyte
)

Common binary data sizes

Variables

This section is empty.

Functions

This section is empty.

Types

type Size

type Size uint64

Size represents the size of data in bytes.

func Flag

func Flag(name, value, description string) *Size

Flag defines a Size flag with specified name, default value, and usage string.

func FlagVar added in v0.0.64

func FlagVar(fs *flag.FlagSet, s *Size, name string, value Size, description string) *Size

FlagVar defines a Size flag with specified name, default value, and usage string into the provided FlagSet.

func Parse

func Parse(s string) (Size, error)

Parse parses a Size from a string. A Size is an unsigned decimal number with an optional fraction and a unit suffix. Examples: "0", "10B", "1kB", "4GB", "5GiB". Valid units are "B", (decimal: "kB", "MB", "GB, "TB, "PB"), (binary: "KiB", "MiB", "GiB", "TiB", "PiB")

func (Size) Bytes

func (s Size) Bytes() uint64

Bytes returns s in the equivalent number of bytes.

func (Size) Floor added in v0.0.59

func (s Size) Floor() Size

Floor returns a Size nearest to a whole unit less than or equal to itself.

func (Size) Gibibytes

func (s Size) Gibibytes() float64

Gibibytes returns s in the equivalent number of gibibytes.

func (Size) Gigabytes

func (s Size) Gigabytes() float64

Gigabytes returns s in the equivalent number of gigabytes.

func (Size) Kibibytes

func (s Size) Kibibytes() float64

Kibibytes returns s in the equivalent number of kibibytes.

func (Size) Kilobytes

func (s Size) Kilobytes() float64

Kilobytes returns s in the equivalent number of kilobytes.

func (Size) Mebibytes

func (s Size) Mebibytes() float64

Mebibytes returns s in the equivalent number of mebibytes.

func (Size) Megabytes

func (s Size) Megabytes() float64

Megabytes returns s in the equivalent number of megabytes.

func (Size) Pebibytes

func (s Size) Pebibytes() float64

Pebibytes returns s in the equivalent number of pebibytes.

func (Size) Petabytes

func (s Size) Petabytes() float64

Petabytes returns s in the equivalent number of petabytes.

func (Size) Round added in v0.0.59

func (s Size) Round() Size

Round returns a Size nearest to a whole unit.

func (Size) String

func (s Size) String() string

String implements the Stringer interface.

func (Size) Tebibytes

func (s Size) Tebibytes() float64

Tebibytes returns s in the equivalent number of tebibytes.

func (Size) Terabytes

func (s Size) Terabytes() float64

Terabytes returns s in the equivalent number of terabytes.

Jump to

Keyboard shortcuts

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