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'.
go get -u gangleri.io/pkg/humanbytes
To convert a string such as 1 KB
into bytes:
b, err := humanbytes.ParseBytes("1 KB") // 1024
To convert the bytes into another unit e.g. KB
:
kb, err := humanbytes.Convert(1048576, "MB") // 1MB
s, err := humanbytes.Sprint(1024, "KB") // 1KB
BSD-2-Clause