humanize

package
v2.5.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: MIT Imports: 7 Imported by: 51

Documentation

Overview

package humanize is designed to parse and format "humanized" versions of numbers with units.

Based on: github.com/dustin/go-humanize.

Index

Constants

View Source
const (
	Byte = 1 << (iota * 10)
	Kibibyte
	Mebibyte
	Gibibyte
	Tebibyte
	Pebibyte

	Kilobyte = 1000 * Byte
	Megabyte = 1000 * Kilobyte
	Gigabyte = 1000 * Megabyte
	Terabyte = 1000 * Gigabyte
	Petabyte = 1000 * Terabyte
)

Variables

This section is empty.

Functions

func FormatByteRate

func FormatByteRate(s uint64, d time.Duration) string

FormatByteRate outputs the given rate of transfer "r" as the quotient of "s" (the number of bytes transferred) over "d" (the duration of time that those bytes were transferred in).

It displays the output as a quantity of a "per-unit-time" unit (i.e., B/s, MiB/s) in the most representative fashion possible, as above.

func FormatBytes

func FormatBytes(s uint64) string

FormatBytes outputs the given number of bytes "s" as a human-readable string, rounding to the nearest half within .01.

func FormatBytesUnit

func FormatBytesUnit(s, u uint64) string

FormatBytesUnit outputs the given number of bytes "s" as a quantity of the given units "u" to the nearest half within .01.

func ParseByteUnit

func ParseByteUnit(str string) (uint64, error)

ParseByteUnit returns the number of bytes in a given unit of storage, or an error, if that unit is unrecognized.

func ParseBytes

func ParseBytes(str string) (uint64, error)

ParseBytes parses a given human-readable bytes or ibytes string into a number of bytes, or an error if the string was unable to be parsed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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