size

package module
v0.0.0-...-9fdad82 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2015 License: BSD-3-Clause Imports: 2 Imported by: 0

README

size
====

.. image:: https://travis-ci.org/mattrobenolt/size.svg?branch=master
   :target: https://travis-ci.org/mattrobenolt/size

.. image:: https://godoc.org/github.com/mattrobenolt/size?status.png
   :target: https://godoc.org/github.com/mattrobenolt/size

``size`` is a package for working with byte capacities similar to ``time.Duration``.

Usage
~~~~~

.. code-block:: go

    // Returns a Capacity which is a uint64 representing
    // 5 gigabytes in bytes.
    5*size.Gigabyte

    // Turn the string "5G" into a Capacity
    // Useful for parsing from flags.
    size.ParseCapacity("5G")

Installation
~~~~~~~~~~~~

.. code-block:: console

    $ go get github.com/mattrobenolt/size

Resources
~~~~~~~~~
* `Documentation <http://godoc.org/github.com/mattrobenolt/size>`_

Documentation

Overview

Package size implements functionality for working with byte sizes.

Index

Constants

View Source
const (
	Byte     Capacity = 1
	Kilobyte          = Byte << 10
	Megabyte          = Kilobyte << 10
	Gigabyte          = Megabyte << 10
	Terabyte          = Gigabyte << 10
	Petabyte          = Terabyte << 10
	Exabyte           = Petabyte << 10
)

Common capacities.

To count the number of units in a Capacity, divide:

gigabyte := size.Gigabyte
fmt.Print(gigabyte/size.Kilobyte) // prints 1048576

To convert an integer number of units to a Capacity, multiply:

gigabytes := 5
fmt.Print(gigabytes*size.Gigabyte) // prints 5G

Variables

This section is empty.

Functions

This section is empty.

Types

type Capacity

type Capacity uint64

A Capacity represents a size in bytes.

func ParseCapacity

func ParseCapacity(s string) (Capacity, error)

ParseCapacity parses a capacity string. A capacity string may only contain whole integers and one unit suffix, such as "10G" or "5T". Valid capacity units are "K", "M", "G", "T", "P", "E".

func (Capacity) Bytes

func (c Capacity) Bytes() uint64

Bytes returns the capacity as an integer bytes count.

func (Capacity) Exabytes

func (c Capacity) Exabytes() uint64

Exabytes returns the capacity as an integer exabytes count.

func (Capacity) Gigabytes

func (c Capacity) Gigabytes() uint64

Gigabytes returns the capacity as an integer gigabytes count.

func (Capacity) Kilobytes

func (c Capacity) Kilobytes() uint64

Kilobytes returns the capacity as an integer kilobytes count.

func (Capacity) Megabytes

func (c Capacity) Megabytes() uint64

Megabytes returns the capacity as an integer megabytes count.

func (Capacity) Petabytes

func (c Capacity) Petabytes() uint64

Petabytes returns the capacity as an integer petabytes count.

func (*Capacity) Set

func (c *Capacity) Set(s string) error

Set parses the given string and sets the receiver to the parsed value.

func (Capacity) String

func (c Capacity) String() string

String returns a string representing the capacity in the form of "10.4G". Capacities are rounded to the nearest 1/10th within the largest unit of granularity. This format is similar to the "human" output from common Linux tools.

func (Capacity) Terabytes

func (c Capacity) Terabytes() uint64

Terabytes returns the capacity as an integer terabytes count.

Jump to

Keyboard shortcuts

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