bytesutil

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

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(BinaryFormat(2140))

prints

2.09 KiB

func Compress

func Compress(input []byte) ([]byte, error)

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

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(DecimalFormat(2140))

prints

2.14KB

func Decompress

func Decompress(input []byte) ([]byte, error)

func GenerateRandomBytes

func GenerateRandomBytes(n int) []byte

func RandInt

func RandInt(max int) int

Generate a random integer in the uniform range [0, max).

Types

This section is empty.

Jump to

Keyboard shortcuts

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