utils

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Byte = 1 << (iota * 10)
	KiByte
	MiByte
	GiByte
	TiByte
	PiByte
	EiByte
)

IEC Sizes. kibis of bits

View Source
const (
	IByte = 1
	KByte = IByte * 1000
	MByte = KByte * 1000
	GByte = MByte * 1000
	TByte = GByte * 1000
	PByte = TByte * 1000
	EByte = PByte * 1000
)

SI Sizes.

Variables

This section is empty.

Functions

func Bytes

func Bytes(s uint64) string

Bytes produces a human readable representation of an SI size.

See also: ParseBytes.

Bytes(82854982) -> 83 MB

func ConvertBytesToUint64

func ConvertBytesToUint64(b []byte) uint64

Converts bytes to an integer

func ConvertUint64ToBytes

func ConvertUint64ToBytes(u uint64) []byte

ConvertUint64ToBytes converts uint64 to bytes of 64 bits

func DecodeMsgPack

func DecodeMsgPack(buf []byte, out interface{}) error

Decode reverses the encode operation on a byte slice input

func DirSize

func DirSize(path string) (int64, error)

DirSize returns the total size of all files in the given directory

func EncodeMsgPack

func EncodeMsgPack(in interface{}) (*bytes.Buffer, error)

Encode writes an encoded object to a new bytes buffer

func FriendlyBytes

func FriendlyBytes(n uint64) string

FriendlyBytes produces a human readable representation of an SI size

func IBytes

func IBytes(s uint64) string

IBytes produces a human readable representation of an IEC size.

See also: ParseBytes.

IBytes(82854982) -> 79 MiB

func ParseBytes

func ParseBytes(s string) (uint64, error)

ParseBytes parses a string representation of bytes into the number of bytes it represents.

See Also: Bytes, IBytes.

ParseBytes("42 MB") -> 42000000, nil ParseBytes("42 mib") -> 44040192, nil

func PathExists

func PathExists(p string) bool

PathExists returns true if the given path exists.

func ResolvableAddress

func ResolvableAddress(addr string) (string, error)

ResolvableAddress checks if the host in the given address is DNS-resolvable. Returns the host if resolvable, an error if not.

Types

This section is empty.

Jump to

Keyboard shortcuts

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