gangleri / humanbytes

display number of bytes in human readable format and parse from human readable formats

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Human readable bytes

Build Status Report card codecov GoDoc

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

About

display number of bytes in human readable format and parse from human readable formats

License:BSD 2-Clause "Simplified" License


Languages

Language:Go 100.0%