humanbytes

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2017 License: BSD-2-Clause Imports: 4 Imported by: 0

README

Human readable bytes

Build Status Report card

This package is used to convert bytes to and from human readable representations. It can convert a string such as '1 MB' into bytes. Convert bytes to another unit eg KB, MB, GB... and also generate a human readable representation of the bytes e.g. 1024 would be displayed as '1 KB'.

Installation

go get -u gangleri.io/pkg/humanbytes

Documentation

Parsing

To convert a string such as 1 KB into bytes:

b, err := humanbytes.ParseBytes("1 KB") // 1024
Convert

To convert the bytes into another unit e.g. KB:

kb, err := humanbytes.Convert(1048576, "MB") // 1MB
Sprint
s, err := humanbytes.Sprint(1024, "KB") // 1KB

Licence

BSD-2-Clause

Documentation

Overview

Package humanbytes is used to convert bytes to and from human readable representations. It can convert a string such as '1 MB' into bytes. Convert bytes to another unit eg KB, MB, GB... and also generate a human readable representation of the bytes e.g. 1024 would be displayed as '1 KB'.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(b int, t string) (float64, error)

Convert takes the number of bytes and converts it to the equivalent in the unit identified by the type string parameter e.g. 'KB' or 'MB'

func ConvertToBytes

func ConvertToBytes(x float64, t string) (int, error)

ConvertToBytes takes a value in the specified unit and converts it to bytes

func ParseBytes

func ParseBytes(str string) (int, error)

ParseBytes takes a string with a unit prefix (e.g. MB) and converts the value to bytes

func Sprint

func Sprint(b int, t string) (string, error)

Sprint generates a string representation using the specified unit

Types

This section is empty.

Jump to

Keyboard shortcuts

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