bytefmt

package
v0.0.0-...-1b9e8c6 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BYTE represents one byte.
	BYTE = 1.0

	// KILOBYTE represents kilo bytes.
	KILOBYTE = 1024

	// MEGABYTE represents mega bytes.
	MEGABYTE = 1024 * KILOBYTE

	//GIGABYTE represents giga bytes.
	GIGABYTE = 1024 * MEGABYTE

	// TERABYTE represents tera bytes.
	TERABYTE = 1024 * GIGABYTE
)

Variables

View Source
var ErrorInvalidByte = errors.New("Byte quantity must be a positive integer with a unit of measurement like M, MB, G, or GB")

ErrorInvalidByte is the error that presents the format of string is not a valid byte.

Functions

func ByteSize

func ByteSize(bytes uint64) string

ByteSize returns a human-readable byte string of the form 10M, 12.5K, and so forth. The following units are available:

T: Terabyte
G: Gigabyte
M: Megabyte
K: Kilobyte
B: Byte

The unit that results in the smallest number greater than or equal to 1 is always chosen.

func ToBytes

func ToBytes(s string) (uint64, error)

ToBytes parses a string formatted by ByteSize as bytes.

func ToKilobytes

func ToKilobytes(s string) (uint64, error)

ToKilobytes parses a string formatted by ByteSize as kilobytes.

func ToMegabytes

func ToMegabytes(s string) (uint64, error)

ToMegabytes parses a string formatted by ByteSize as megabytes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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