bsize

package
v0.0.0-...-884a6b9 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package bsize provides typed bytes/size handling and parsing, modeled after time.Duration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bytes

type Bytes uint64
const (
	B   Bytes = 1
	KiB Bytes = 1 << 10
	MiB Bytes = 1 << 20
	GiB Bytes = 1 << 30
	TiB Bytes = 1 << 40
	PiB Bytes = 1 << 50
)

func Parse

func Parse(s string) (Bytes, error)

Parse parses a string of bytes size with an optional unit suffix (e.g. 1024 or 4KiB) into a number of bytes. Returns an error if the result would overflow uint64 (~16384PiB).

func (*Bytes) Set

func (b *Bytes) Set(s string) error

func (Bytes) String

func (b Bytes) String() string

String returns a string representing the byte size in the form "1.5GiB". The fractional digit and decimal point are omitted when the value is an even multiple of the unit. Sizes below 1KiB format as plain bytes. The zero size formats as 0B.

func (*Bytes) Type

func (b *Bytes) Type() string

func (*Bytes) UnmarshalText

func (b *Bytes) UnmarshalText(s []byte) error

Jump to

Keyboard shortcuts

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