bytefmt

package module
v0.0.0-...-f0c8f6e Latest Latest
Warning

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

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

README

bytefmt

Human readable byte formatter

Example:

  bytefmt.ByteSize(100.5*bytefmt.MEGABYTE) // returns "100.5M"
  bytefmt.ByteSize(uint64(1024)) // returns "1K"

For documentation, please see http://godoc.org/github.com/pivotal-golang/bytefmt

Documentation

Overview

Package bytefmt contains helper methods and constants for converting to and from a human-readable byte format.

bytefmt.ByteSize(100.5*bytefmt.MEGABYTE) // "100.5M"
bytefmt.ByteSize(uint64(1024)) // "1K"

Index

Constants

View Source
const (
	BITSPS     = 1.0
	KILOBITSPS = 1000 * BITSPS
	MEGABITSPS = 1000 * KILOBITSPS
	GIGABITSPS = 1000 * MEGABITSPS
	TERABITSPS = 1000 * GIGABITSPS
)
View Source
const (
	BYTE     = 1.0
	KILOBYTE = 1024 * BYTE
	MEGABYTE = 1024 * KILOBYTE
	GIGABYTE = 1024 * MEGABYTE
	TERABYTE = 1024 * GIGABYTE
)

Variables

This section is empty.

Functions

func BPSSize

func BPSSize(bps float64) string

BPSSize returns a human-readable bits/sec string of the form 10Mbps, 12.5Kbps, and so forth. The following units are available:

Tbps: Terabit/sec
Gbps: Gigabit/sec
Mbps: Megabit/sec
Kbps: Kilobit/sec
bps: Bits/sec

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

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 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