bytes

package
Version: v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: MIT Imports: 4 Imported by: 297

README

Bytes

  • Format bytes integer to human readable bytes string.
  • Parse human readable bytes string to bytes integer.

Installation

go get github.com/labstack/gommon/bytes

Usage

Format
println(bytes.Format(13231323))

12.62MB

Parse
b, _ = Parse("2M")
println(b)

2097152

Documentation

Index

Constants

View Source
const (
	KiB
	MiB
	GiB
	TiB
	PiB
	EiB
)

binary units (IEC 60027)

View Source
const (
	KB = 1000
	MB = KB * 1000
	GB = MB * 1000
	TB = GB * 1000
	PB = TB * 1000
	EB = PB * 1000
)

decimal units (SI international system of units)

Variables

This section is empty.

Functions

func Format

func Format(value int64) string

Format wraps global Bytes's Format function.

func FormatBinary added in v0.4.0

func FormatBinary(value int64) string

FormatBinary wraps global Bytes's FormatBinary function.

func FormatDecimal added in v0.4.0

func FormatDecimal(value int64) string

FormatDecimal wraps global Bytes's FormatDecimal function.

func Parse

func Parse(value string) (int64, error)

Parse wraps global Bytes's Parse function.

Types

type Bytes

type Bytes struct{}

Bytes struct

func New

func New() *Bytes

New creates a Bytes instance.

func (*Bytes) Format

func (b *Bytes) Format(value int64) string

Format formats bytes integer to human readable string according to IEC 60027. For example, 31323 bytes will return 30.59KB.

func (*Bytes) FormatBinary added in v0.4.0

func (*Bytes) FormatBinary(value int64) string

FormatBinary formats bytes integer to human readable string according to IEC 60027. For example, 31323 bytes will return 30.59KB.

func (*Bytes) FormatDecimal added in v0.4.0

func (*Bytes) FormatDecimal(value int64) string

FormatDecimal formats bytes integer to human readable string according to SI international system of units. For example, 31323 bytes will return 31.32KB.

func (*Bytes) Parse

func (b *Bytes) Parse(value string) (int64, error)

Parse parses human readable bytes string to bytes integer. For example, 6GiB (6Gi is also valid) will return 6442450944, and 6GB (6G is also valid) will return 6000000000.

func (*Bytes) ParseBinary added in v0.4.0

func (*Bytes) ParseBinary(value string) (i int64, err error)

ParseBinary parses human readable bytes string to bytes integer. For example, 6GiB (6Gi is also valid) will return 6442450944.

func (*Bytes) ParseDecimal added in v0.4.0

func (*Bytes) ParseDecimal(value string) (i int64, err error)

ParseDecimal parses human readable bytes string to bytes integer. For example, 6GB (6G is also valid) will return 6000000000.

Source Files

Jump to

Keyboard shortcuts

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