bytes

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2018 License: MIT Imports: 3 Imported by: 392 modules, 395 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 (
	KB
	MB
	GB
	TB
	PB
	EB
)

Variables

This section is empty.

Functions

func Format

func Format(b int64) string

Format wraps global Bytes's Format function.

func Parse

func Parse(val 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 (*Bytes) Format(b int64) string

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

func (*Bytes) Parse

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

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

Jump to

Keyboard shortcuts

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