bytesize

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package bytesize provides functionality for measuring and formatting byte sizes.

You can also perform mathematical operation with ByteSize's and the result will be a valid ByteSize with the correct size suffix.

Index

Constants

This section is empty.

Variables

View Source
var (
	// LongUnits Use long units, such as "megabytes" instead of "MB".
	LongUnits = false

	// Format String format of bytesize output. The unit of measure will be appended
	// to the end. Uses the same formatting options as the fmt package.
	Format = "%.2f"
)

Functions

This section is empty.

Types

type ByteSize

type ByteSize uint64

ByteSize represents a number of bytes

const (
	B  ByteSize = 1
	KB ByteSize = 1 << (10 * iota)
	MB
	GB
	TB
	PB
	EB
)

Byte size suffixes.

func New

func New(s float64) ByteSize

New returns a new ByteSize type set to s.

func Parse

func Parse(s string) (ByteSize, error)

Parse parses a byte size string. A byte size string is a number followed by a unit suffix, such as "1024B" or "1 MB". Valid byte units are "B", "KB", "MB", "GB", "TB", "PB" and "EB". You can also use the long format of units, such as "kilobyte" or "kilobytes".

func (ByteSize) Format

func (b ByteSize) Format(format string, unit string, longUnits bool) string

Format Returns a string representation of b with the specified formatting and units.

func (*ByteSize) Get

func (b *ByteSize) Get() interface{}

Get Satisfy the flag package Getter interface.

func (*ByteSize) Set

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

Set Satisfy the flag package Value interface.

func (ByteSize) String

func (b ByteSize) String() string

String returns the string form of b using the package global Format and LongUnits options.

func (*ByteSize) Type

func (b *ByteSize) Type() string

Type Satisfy the flag package Value interface.

func (*ByteSize) UnmarshalText

func (b *ByteSize) UnmarshalText(text []byte) error

UnmarshalText Satisfy the encoding.TextUnmarshaler interface.

Jump to

Keyboard shortcuts

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