cunits

package module
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2019 License: MIT Imports: 4 Imported by: 3

README

ComputerUnits

GoDoc

ComputerUnits allows to manipulate binary and decimal representations of bits and bytes.

Constants example

fmt.Println(cunits.Kbit)
fmt.Println(cunits.Kibit)
fmt.Println(cunits.KB)
fmt.Println(cunits.KiB)
fmt.Printf("1000 MiB = %f MB\n", float64(1000)*cunits.MiB/cunits.MB)

will output:

1000
1024
8000
8192
1000 MiB = 1048.576000 MB

Custom type example

size := cunits.Bit(58) * cunits.MiB
fmt.Println(size.Mbit())
fmt.Println(size.GiBString())

will output:

486.539264
0.06 GiB

Parsing example

size, err := cunits.Parse("7632 MiB")
if err != nil {
    panic(err)
}
fmt.Println(size)
fmt.Println(size.KiB())
fmt.Println(size.KbitString())

will output:

7.45 GiB
7.815168e+06
64021856.26 Kbit

Documentation

Index

Constants

View Source
const (
	// Kbit represents a kilobit
	Kbit = 1000
	// Mbit represents a megabit
	Mbit = 1000000
	// Gbit represents a gigabit
	Gbit = 1000000000
	// Tbit represents a terabit
	Tbit = 1000000000000
	// Pbit represents a petabit
	Pbit = 1000000000000000
	// Ebit represents an exabit
	Ebit = 1000000000000000000
	// Zbit represents a zettabit (overflows int64)
	Zbit = 1000000000000000000000
	// Ybit represents a yottabit (overflows int64)
	Ybit = 1000000000000000000000000
)

Decimal prefix of bits

View Source
const (
	// Kibit represents a kibibit
	Kibit = 1 << 10
	// Mibit represents a mebibit
	Mibit = 1 << 20
	// Gibit represents a gibibit
	Gibit = 1 << 30
	// Tibit represents a tebibit
	Tibit = 1 << 40
	// Pibit represents a pebibit
	Pibit = 1 << 50
	// Eibit represents an exbibit
	Eibit = 1 << 60
	// Zibit represents a zebibit (overflows int64)
	Zibit = 1 << 70
	// Yibit represents a yobibit (overflows int64)
	Yibit = 1 << 80
)

Binary prefix of bits

View Source
const (
	// KB represents a kilobyte
	KB = Kbit * Byte
	// MB represents a megabyte
	MB = Mbit * Byte
	// GB represents a gigabyte
	GB = Gbit * Byte
	// TB represents a terabyte
	TB = Tbit * Byte
	// PB represents a petabyte
	PB = Pbit * Byte
	// EB represents an exabyte
	EB = Ebit * Byte
	// ZB represents a zettabyte (overflows int64)
	ZB = Zbit * Byte
	// YB represents a yottabyte (overflows int64)
	YB = Ybit * Byte
)

Decimal prefix of bytes

View Source
const (
	// KiB represents a kibibyte
	KiB = Kibit * Byte
	// MiB represents a mebibyte
	MiB = Mibit * Byte
	// GiB represents a gibibyte
	GiB = Gibit * Byte
	// TiB represents a tebibyte
	TiB = Tibit * Byte
	// PiB represents a pebibyte
	PiB = Pibit * Byte
	// EiB represents an exbibyte (overflows int64)
	EiB = Eibit * Byte
	// ZiB represents a zebibyte (overflows int64)
	ZiB = Zbit * Byte
	// YiB represents a yobibyte (overflows int64)
	YiB = Ybit * Byte
)

Binary prefix of bytes

View Source
const Byte = 8

Byte represent a byte

Variables

This section is empty.

Functions

This section is empty.

Types

type Bits

type Bits uint64

Bits represent a size in bits

func ImportInByte

func ImportInByte(sizeInByte float64) Bits

ImportInByte imports a number in byte

func ImportInEB

func ImportInEB(sizeInEB float64) Bits

ImportInEB imports a number in exabyte

func ImportInEbit

func ImportInEbit(sizeInEbit float64) Bits

ImportInEbit imports a number in exabit

func ImportInEiB

func ImportInEiB(sizeInEiB float64) Bits

ImportInEiB imports a number in exabyte (sizeInEiB better < 1)

func ImportInEibit

func ImportInEibit(sizeInEibit float64) Bits

ImportInEibit imports a number in exbibit

func ImportInGB

func ImportInGB(sizeInGB float64) Bits

ImportInGB imports a number in gigabyte

func ImportInGbit

func ImportInGbit(sizeInGbit float64) Bits

ImportInGbit imports a number in gigabit

func ImportInGiB

func ImportInGiB(sizeInGiB float64) Bits

ImportInGiB imports a number in gigabyte

func ImportInGibit

func ImportInGibit(sizeInGibit float64) Bits

ImportInGibit imports a number in gibibit

func ImportInKB

func ImportInKB(sizeInKB float64) Bits

ImportInKB imports a number in kilobyte

func ImportInKbit

func ImportInKbit(sizeInKbit float64) Bits

ImportInKbit imports a number in kilobit

func ImportInKiB

func ImportInKiB(sizeInKiB float64) Bits

ImportInKiB imports a number in kilobyte

func ImportInKibit

func ImportInKibit(sizeInKibit float64) Bits

ImportInKibit imports a number in kibibit

func ImportInMB

func ImportInMB(sizeInMB float64) Bits

ImportInMB imports a number in megabyte

func ImportInMbit

func ImportInMbit(sizeInMbit float64) Bits

ImportInMbit imports a number in megabit

func ImportInMiB

func ImportInMiB(sizeInMiB float64) Bits

ImportInMiB imports a number in megabyte

func ImportInMibit

func ImportInMibit(sizeInMibit float64) Bits

ImportInMibit imports a number in mebibit

func ImportInPB

func ImportInPB(sizeInPB float64) Bits

ImportInPB imports a number in petabyte

func ImportInPbit

func ImportInPbit(sizeInPbit float64) Bits

ImportInPbit imports a number in petabit

func ImportInPiB

func ImportInPiB(sizeInPiB float64) Bits

ImportInPiB imports a number in petabyte

func ImportInPibit

func ImportInPibit(sizeInPibit float64) Bits

ImportInPibit imports a number in pebibit

func ImportInTB

func ImportInTB(sizeInTB float64) Bits

ImportInTB imports a number in terabyte

func ImportInTbit

func ImportInTbit(sizeInTbit float64) Bits

ImportInTbit imports a number in terabit

func ImportInTiB

func ImportInTiB(sizeInTiB float64) Bits

ImportInTiB imports a number in terabyte

func ImportInTibit

func ImportInTibit(sizeInTibit float64) Bits

ImportInTibit imports a number in tebibit

func ImportInYB

func ImportInYB(sizeInYB float64) Bits

ImportInYB imports a number in yottabyte (sizeInYB better < 1)

func ImportInYbit

func ImportInYbit(sizeInYbit float64) Bits

ImportInYbit imports a number in yottabit (sizeInYbit better < 1)

func ImportInYiB

func ImportInYiB(sizeInYiB float64) Bits

ImportInYiB imports a number in yottabyte (sizeInYiB better < 1)

func ImportInYibit

func ImportInYibit(sizeInYibit float64) Bits

ImportInYibit imports a number in yobibit (sizeInYibit better < 1)

func ImportInZB

func ImportInZB(sizeInZB float64) Bits

ImportInZB imports a number in zettabyte (sizeInZB better < 1)

func ImportInZbit

func ImportInZbit(sizeInZbit float64) Bits

ImportInZbit imports a number in zettabit (sizeInZbit better < 1)

func ImportInZiB

func ImportInZiB(sizeInZiB float64) Bits

ImportInZiB imports a number in zettabyte (sizeInZiB better < 1)

func ImportInZibit

func ImportInZibit(sizeInZibit float64) Bits

ImportInZibit imports a number in zebibit (sizeInZibit better < 1)

func Parse

func Parse(sizeSuffix string) (size Bits, err error)

Parse parses un string representation of a number with a suffix

func (Bits) BitString

func (size Bits) BitString() string

BitString returns the size in bit with unit suffix

func (Bits) Byte

func (size Bits) Byte() float64

Byte returns the size in byte

func (Bits) ByteString

func (size Bits) ByteString() string

ByteString returns the size in byte with unit suffix

func (Bits) EB

func (size Bits) EB() float64

EB returns the size in exabyte

func (Bits) EBString

func (size Bits) EBString() string

EBString returns the size in exabyte with unit suffix

func (Bits) Ebit

func (size Bits) Ebit() float64

Ebit returns the size in exabit

func (Bits) EbitString

func (size Bits) EbitString() string

EbitString returns the size in exabit with unit suffix

func (Bits) EiB

func (size Bits) EiB() float64

EiB returns the size in exbibyte

func (Bits) EiBString

func (size Bits) EiBString() string

EiBString returns the size in exbibyte with unit suffix (carefull with sub zeros !)

func (Bits) Eibit

func (size Bits) Eibit() float64

Eibit returns the size in exbibit

func (Bits) EibitString

func (size Bits) EibitString() string

EibitString returns the size in exbibit with unit suffix

func (Bits) GB

func (size Bits) GB() float64

GB returns the size in gigabyte

func (Bits) GBString

func (size Bits) GBString() string

GBString returns the size in gigabyte with unit suffix

func (Bits) Gbit

func (size Bits) Gbit() float64

Gbit returns the size in gigabit

func (Bits) GbitString

func (size Bits) GbitString() string

GbitString returns the size in gigabit with unit suffix

func (Bits) GetHumanSizeRepresentation

func (size Bits) GetHumanSizeRepresentation() string

GetHumanSizeRepresentation returns the size in a human readable binary prefix of bytes format

func (Bits) GetHumanSpeedRepresentation

func (size Bits) GetHumanSpeedRepresentation() string

GetHumanSpeedRepresentation returns the size in a human readable decimal prefix of bits format

func (Bits) GiB

func (size Bits) GiB() float64

GiB returns the size in gibibyte

func (Bits) GiBString

func (size Bits) GiBString() string

GiBString returns the size in gibibyte with unit suffix

func (Bits) Gibit

func (size Bits) Gibit() float64

Gibit returns the size in gibibit

func (Bits) GibitString

func (size Bits) GibitString() string

GibitString returns the size in gibibit with unit suffix

func (Bits) KB

func (size Bits) KB() float64

KB returns the size in kilobyte

func (Bits) KBString

func (size Bits) KBString() string

KBString returns the size in kilobyte with unit suffix

func (Bits) Kbit

func (size Bits) Kbit() float64

Kbit returns the size in kilobit

func (Bits) KbitString

func (size Bits) KbitString() string

KbitString returns the size in kilobit with unit suffix

func (Bits) KiB

func (size Bits) KiB() float64

KiB returns the size in kibibyte

func (Bits) KiBString

func (size Bits) KiBString() string

KiBString returns the size in kibibyte with unit suffix

func (Bits) Kibit

func (size Bits) Kibit() float64

Kibit returns the size in kibibit

func (Bits) KibitString

func (size Bits) KibitString() string

KibitString returns the size in kibibit with unit suffix

func (Bits) MB

func (size Bits) MB() float64

MB returns the size in megabyte

func (Bits) MBString

func (size Bits) MBString() string

MBString returns the size in megabyte with unit suffix

func (Bits) Mbit

func (size Bits) Mbit() float64

Mbit returns the size in megabit

func (Bits) MbitString

func (size Bits) MbitString() string

MbitString returns the size in megabit with unit suffix

func (Bits) MiB

func (size Bits) MiB() float64

MiB returns the size in mebibyte

func (Bits) MiBString

func (size Bits) MiBString() string

MiBString returns the size in mebibyte with unit suffix

func (Bits) Mibit

func (size Bits) Mibit() float64

Mibit returns the size in mebibit

func (Bits) MibitString

func (size Bits) MibitString() string

MibitString returns the size in mebibit with unit suffix

func (Bits) PB

func (size Bits) PB() float64

PB returns the size in petabyte

func (Bits) PBString

func (size Bits) PBString() string

PBString returns the size in petabyte with unit suffix

func (Bits) Pbit

func (size Bits) Pbit() float64

Pbit returns the size in petabit

func (Bits) PbitString

func (size Bits) PbitString() string

PbitString returns the size in petabit with unit suffix

func (Bits) PiB

func (size Bits) PiB() float64

PiB returns the size in pebibyte

func (Bits) PiBString

func (size Bits) PiBString() string

PiBString returns the size in pebibyte with unit suffix

func (Bits) Pibit

func (size Bits) Pibit() float64

Pibit returns the size in pebibit

func (Bits) PibitString

func (size Bits) PibitString() string

PibitString returns the size in pebibit with unit suffix

func (Bits) String

func (size Bits) String() string

String allows direct reprensetation of Bit by calling GetHumanSizeRepresentation()

func (Bits) TB

func (size Bits) TB() float64

TB returns the size in terabyte

func (Bits) TBString

func (size Bits) TBString() string

TBString returns the size in terabyte with unit suffix

func (Bits) Tbit

func (size Bits) Tbit() float64

Tbit returns the size in terabit

func (Bits) TbitString

func (size Bits) TbitString() string

TbitString returns the size in terabit with unit suffix

func (Bits) TiB

func (size Bits) TiB() float64

TiB returns the size in tebibyte

func (Bits) TiBString

func (size Bits) TiBString() string

TiBString returns the size in tebibyte wit unit suffix

func (Bits) Tibit

func (size Bits) Tibit() float64

Tibit returns the size in tebibit

func (Bits) TibitString

func (size Bits) TibitString() string

TibitString returns the size in tebibit with unit suffix

func (Bits) YB

func (size Bits) YB() float64

YB returns the size in yottabyte

func (Bits) YBString

func (size Bits) YBString() string

YBString returns the size in yottabyte with unit suffix (carefull with sub zeros !)

func (Bits) Ybit

func (size Bits) Ybit() float64

Ybit returns the size in yottabit

func (Bits) YbitString

func (size Bits) YbitString() string

YbitString returns the size in yottabit with unit suffix (carefull with sub zeros !)

func (Bits) YiB

func (size Bits) YiB() float64

YiB returns the size in yobibyte

func (Bits) YiBString

func (size Bits) YiBString() string

YiBString returns the size in yobibyte with unit suffix (carefull with sub zeros !)

func (Bits) Yibit

func (size Bits) Yibit() float64

Yibit returns the size in yobibit

func (Bits) YibitString

func (size Bits) YibitString() string

YibitString returns the size in yobibit with unit suffix (carefull with sub zeros !)

func (Bits) ZB

func (size Bits) ZB() float64

ZB returns the size in zettabyte

func (Bits) ZBString

func (size Bits) ZBString() string

ZBString returns the size in zettabyte with unit suffix (carefull with sub zeros !)

func (Bits) Zbit

func (size Bits) Zbit() float64

Zbit returns the size in zettabit

func (Bits) ZbitString

func (size Bits) ZbitString() string

ZbitString returns the size in zettabit with unit suffix (carefull with sub zeros !)

func (Bits) ZiB

func (size Bits) ZiB() float64

ZiB returns the size in zebibyte

func (Bits) ZiBString

func (size Bits) ZiBString() string

ZiBString returns the size in zebibyte with unit suffix (carefull with sub zeros !)

func (Bits) Zibit

func (size Bits) Zibit() float64

Zibit returns the size in zebibit

func (Bits) ZibitString

func (size Bits) ZibitString() string

ZibitString returns the size in zebibit with unit suffix (carefull with sub zeros !)

Jump to

Keyboard shortcuts

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