bytesutil

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package bytesutil helps you convert byte sizes (such as file size, data uploaded/downloaded etc.) to human-readable strings. This allows conversion to decimal and binary formats.

See: https://en.m.wikipedia.org/wiki/Byte#Multiple-byte_units

Index

Constants

View Source
const (
	KILO int64 = 1000        // 1000 power 1 (10 power 3)
	KIBI int64 = 1024        // 1024 power 1 (2 power 10)
	MEGA       = KILO * KILO // 1000 power 2 (10 power 6)
	MEBI       = KIBI * KIBI // 1024 power 2 (2 power 20)
	GIGA       = MEGA * KILO // 1000 power 3 (10 power 9)
	GIBI       = MEBI * KIBI // 1024 power 3 (2 power 30)
	TERA       = GIGA * KILO // 1000 power 4 (10 power 12)
	TEBI       = GIBI * KIBI // 1024 power 4 (2 power 40)
	PETA       = TERA * KILO // 1000 power 5 (10 power 15)
	PEBI       = TEBI * KIBI // 1024 power 5 (2 power 50)
	EXA        = PETA * KILO // 1000 power 6 (10 power 18)
	EXBI       = PEBI * KIBI // 1024 power 6 (2 power 60)
)

Constants for byte sizes in decimal and binary formats

Variables

This section is empty.

Functions

func BinaryFormat

func BinaryFormat(size int64) string

BinaryFormat formats a byte size to a human-readable string in binary format. Uses binary prefixes. See: https://en.m.wikipedia.org/wiki/Binary_prefix

For example,

fmt.Println(bytesutil.BinaryFormat(2140))

prints

2.09 KiB

func DecimalFormat

func DecimalFormat(size int64) string

DecimalFormat formats a byte size to a human-readable string in decimal format. Uses metric prefixes. See: https://en.m.wikipedia.org/wiki/Metric_prefix

For example,

fmt.Println(bytesutil.DecimalFormat(2140))

prints

2.14KB

Types

This section is empty.

Jump to

Keyboard shortcuts

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