bytex

package
v1.0.75 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Buffer32k = sync.Pool{
	New: func() any {
		return make([]byte, 32*KiB)
	},
}

Buffer32k pool to reduce memory pressure when handling large amount of file operations (32KB buffers)

Functions

This section is empty.

Types

type Size

type Size int64

Size represents a byte size. The representation limits the largest representable size to approximately 8 exabytes.

const (
	B   Size = 1
	KB  Size = 1000
	KiB Size = 1024
	MB  Size = 1000 * KB
	MiB Size = 1024 * KiB
	GB  Size = 1000 * MB
	GiB Size = 1024 * MiB
	TB  Size = 1000 * GB
	TiB Size = 1024 * GiB
	PB  Size = 1000 * TB
	PiB Size = 1024 * TiB
	EB  Size = 1000 * PB
	EiB Size = 1024 * PiB
)

func ParseSize

func ParseSize(s string) (Size, error)

ParseSize parses a size string. A size string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300KB", "1.5GiB" or "2.5MB". Valid size units are "B", "KB", "KiB", "MB", "MiB", "GB", "GiB", "TB", "TiB", "PB", "PiB", "EB", "EiB".

func (Size) Bytes

func (s Size) Bytes() float64

Bytes returns the size as a floating-point number of bytes.

func (Size) BytesString

func (s Size) BytesString() string

BytesString returns the size as a string with "B" suffix.

func (Size) Exabytes

func (s Size) Exabytes() float64

Exabytes returns the size as a floating-point number of exabytes.

func (Size) Exbibytes

func (s Size) Exbibytes() float64

Exbibytes returns the size as a floating-point number of exbibytes.

func (Size) Format

func (s Size) Format(unit Size, precision ...int) string

Format returns the size formatted with the specified unit. The unit should be one of: B, KB, KiB, MB, MiB, GB, GiB, TB, TiB, PB, PiB, EB, EiB. Precision is optional - if not provided or negative, it defaults to defaultPrecision.

func (Size) Gibibytes

func (s Size) Gibibytes() float64

Gibibytes returns the size as a floating-point number of gibibytes.

func (Size) Gigabytes

func (s Size) Gigabytes() float64

Gigabytes returns the size as a floating-point number of gigabytes.

func (Size) HumanReadable

func (s Size) HumanReadable() string

HumanReadable returns a human-readable string using the highest appropriate unit with fractions. It automatically selects the best unit that keeps the value >= 1.

func (Size) Kibibytes

func (s Size) Kibibytes() float64

Kibibytes returns the size as a floating-point number of kibibytes.

func (Size) Kilobytes

func (s Size) Kilobytes() float64

Kilobytes returns the size as a floating-point number of kilobytes.

func (Size) Mebibytes

func (s Size) Mebibytes() float64

Mebibytes returns the size as a floating-point number of mebibytes.

func (Size) Megabytes

func (s Size) Megabytes() float64

Megabytes returns the size as a floating-point number of megabytes.

func (Size) Pebibytes

func (s Size) Pebibytes() float64

Pebibytes returns the size as a floating-point number of pebibytes.

func (Size) Petabytes

func (s Size) Petabytes() float64

Petabytes returns the size as a floating-point number of petabytes.

func (Size) String

func (s Size) String() string

String returns a string representation of the size. It uses the largest unit that evenly divides the size.

func (Size) Tebibytes

func (s Size) Tebibytes() float64

Tebibytes returns the size as a floating-point number of tebibytes.

func (Size) Terabytes

func (s Size) Terabytes() float64

Terabytes returns the size as a floating-point number of terabytes.

Jump to

Keyboard shortcuts

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