bytes

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

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

Based on https://github.com/cloudfoundry/bytefmt. Synced at https://github.com/cloudfoundry/bytefmt/compare/cf55d5288a48262e16d2e628b6221dd2df67bcd1...master. Original license: https://github.com/cloudfoundry/bytefmt/blob/master/LICENSE.

Index

Constants

View Source
const (
	Byte = 1 << (10 * iota)
	Kilobyte
	Megabyte
	Gigabyte
	Terabyte
	Petabyte
	Exabyte
)
View Source
const ErrInvalidByteQuantity errors.Message = "byte quantity must be a positive integer with a unit of measurement like M, MB, MiB, etc"

ErrInvalidByteQuantity is returned by the ParseSize when the passed string is invalid.

Variables

This section is empty.

Functions

This section is empty.

Types

type Size

type Size uint64

A Size represents a size of digital information.

func ParseSize

func ParseSize(s string) (Size, error)

ParseSize parses a string formatted by Size as bytes. Note binary-prefixed and SI prefixed units both mean a base-2 units

KB = K = KiB = 1024
MB = M = MiB = 1024 * K
GB = G = GiB = 1024 * M
TB = T = TiB = 1024 * G
PB = P = PiB = 1024 * T
EB = E = EiB = 1024 * P

func (Size) String

func (size Size) String() string

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

E: Exabyte
P: Petabyte
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.

Jump to

Keyboard shortcuts

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