units

package module
v0.0.0-...-6950e57 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2018 License: MIT Imports: 4 Imported by: 40 modules, 85 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Simple byte size formatting.

This package implements types that can be used in stdlib formatting functions like fmt.Printf to control the output of the expected printed string.

Floating point flags %f and %g print the value in using the correct unit suffix. Decimal units are default, # switches to binary units. If a value is best represented as full bytes, integer bytes are printed instead.

Examples:

fmt.Printf("%.2f", 123 * B)   => "123B"
fmt.Printf("%.2f", 1234 * B)  => "1.23kB"
fmt.Printf("%g", 1200 * B)    => "1.2kB"
fmt.Printf("%#g", 1024 * B)   => "1KiB"

Integer flag %d always prints the value in bytes. # flag adds an unit prefix.

Examples:

fmt.Printf("%d", 1234 * B)    => "1234"
fmt.Printf("%#d", 1234 * B)   => "1234B"

%v is equal to %g

Documentation

Overview

Simple byte size formatting.

This package implements types that can be used in stdlib formatting functions like `fmt.Printf` to control the output of the expected printed string.

Floating point flags %f and %g print the value in using the correct unit suffix. Decimal units are default, # switches to binary units. If a value is best represented as full bytes, integer bytes are printed instead.

Examples:
	fmt.Printf("%.2f", 123 * B)   => "123B"
	fmt.Printf("%.2f", 1234 * B)  => "1.23kB"
	fmt.Printf("%g", 1200 * B)    => "1.2kB"
	fmt.Printf("%#g", 1024 * B)   => "1KiB"

Integer flag %d always prints the value in bytes. # flag adds an unit prefix.

Examples:
	fmt.Printf("%d", 1234 * B)    => "1234"
	fmt.Printf("%#d", 1234 * B)   => "1234B"

%v is equal to %g

Index

Constants

View Source
const (
	B Bytes = 1 << (10 * iota)
	KiB
	MiB
	GiB
	TiB
	PiB
	EiB

	KB = 1e3 * B
	MB = 1e3 * KB
	GB = 1e3 * MB
	TB = 1e3 * GB
	PB = 1e3 * TB
	EB = 1e3 * PB
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bytes

type Bytes int64

func (Bytes) Format

func (b Bytes) Format(f fmt.State, c rune)

Jump to

Keyboard shortcuts

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