Thanks to visit codestin.com
Credit goes to github.com

Skip to content

linkdata/bytecount

Repository files navigation

build coverage goreport Docs

bytecount

Go pretty printer for byte counts.

Only depends on the standard library.

Usage

go get github.com/linkdata/bytecount

When printing byte counts using the fmt package, pass the values using bytecount.N(n).

You may pass width and precision if you wish. The default is to keep the output to a maximum of six characters while still showing as much precision as possible. The highest byte count printable is 268435440QB (Quetta-bytes, 10³⁰), exceeding this will print +InfQB.

If the formatting verb is d (e.g. "%d"), the divisor is 1000 rather than 1024.

If the formatting verb is b (e.g. "%b"), the value is multiplied by 8 and the unit suffix is changed from B (bytes) to b (bits).

If the "#" flag is given, no unit suffix is written.

If the " " flag is given, a space is written between the digits and the suffix.

Example

import (
	"fmt"

	"github.com/linkdata/bytecount"
)

func main() {
	fmt.Print(bytecount.N(53667551))
	// Output:
	// 51.2MB
}

About

Human readable byte count using KB, MB, GB etc

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages