diskusage

package
v0.0.0-...-e2c53ed Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 3 Imported by: 2

README

Package cloudeng.io/file/diskusage

import cloudeng.io/file/diskusage

Functions

Func ParseToBytes
func ParseToBytes(val string) (float64, error)

Types

Type Base2Bytes
type Base2Bytes int64

Base2Bytes represents a number of bytes in base 2.

Constants
KiB, MiB, GiB, TiB, PiB, EiB
KiB Base2Bytes = 1024
MiB Base2Bytes = KiB * 1024
GiB Base2Bytes = MiB * 1024
TiB Base2Bytes = GiB * 1024
PiB Base2Bytes = TiB * 1024
EiB Base2Bytes = PiB * 1024

Values for Base2Bytes.

Methods
func (b Base2Bytes) Num(value int64) float64
func (b Base2Bytes) Standardize() (float64, string)
Type Block
type Block struct {
	// contains filtered or unexported fields
}
Methods
func (s Block) Calculate(_, blocks int64) int64
func (s Block) String() string
Type Calculator
type Calculator interface {
	Calculate(bytes, blocks int64) int64
	String() string
}

Calculator is used to calculate the size of a file or directory based on either its size in bytes (often referred to as its apparent size) and/or the number of storage blocks it occupies. Some file systems support sparse files (most unix filesystems) where the number of blocks occupied by a file is less than the number of bytes it represents, hence, the term 'apparent size'.

Functions
func NewBlock(blocksize int64) Calculator

Block uses the number of blocks occupied by a file to calculate its size.

func NewIdentity() Calculator
func NewRAID0(stripeSize int64, numStripes int) Calculator
func NewRoundup(blocksize int64) Calculator
Type DecimalBytes
type DecimalBytes int64

Base2Bytes represents a number of bytes in base 10.

Constants
KB, MB, GB, TB, PB, EB
KB DecimalBytes = 1000
MB DecimalBytes = KB * 1000
GB DecimalBytes = MB * 1000
TB DecimalBytes = GB * 1000
PB DecimalBytes = TB * 1000
EB DecimalBytes = PB * 1000

Values for DecimalBytes.

Methods
func (b DecimalBytes) Num(value int64) float64
func (b DecimalBytes) Standardize() (float64, string)
Type Identity
type Identity struct{}

Identity returns the apparent size of a file.

Methods
func (i Identity) Calculate(bytes, _ int64) int64
func (i Identity) String() string
Type RAID0
type RAID0 struct {
	// contains filtered or unexported fields
}

RAID0 is a calculator for RAID0 volumes based on the apparent size of the file and the RAID0 stripe size and number of stripes.

Methods
func (r0 RAID0) Calculate(size, _ int64) int64
func (r0 RAID0) String() string
Type Roundup
type Roundup struct {
	// contains filtered or unexported fields
}

Roundup rounds up the apparent size of a file to the nearest block size multiple.

Methods
func (s Roundup) Calculate(bytes, _ int64) int64
func (s Roundup) String() string

Examples

ExampleBase2Bytes
ExampleDecimalBytes

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseToBytes

func ParseToBytes(val string) (float64, error)

Types

type Base2Bytes

type Base2Bytes int64

Base2Bytes represents a number of bytes in base 2.

Example
package main

import (
	"fmt"

	"cloudeng.io/file/diskusage"
)

func main() {
	fmt.Println(diskusage.KiB.Num(512))
	fmt.Println(diskusage.KiB.Num(2048))
	fmt.Println(diskusage.GiB.Num(1073741824))
	fmt.Println(diskusage.Base2Bytes(1024).Standardize())
	fmt.Println(diskusage.Base2Bytes(1536).Standardize())
	fmt.Println(diskusage.Base2Bytes(1610612736).Standardize())
}
Output:

0.5
2
1
1 KiB
1.5 KiB
1.5 GiB
const (
	KiB Base2Bytes = 1024
	MiB Base2Bytes = KiB * 1024
	GiB Base2Bytes = MiB * 1024
	TiB Base2Bytes = GiB * 1024
	PiB Base2Bytes = TiB * 1024
	EiB Base2Bytes = PiB * 1024
)

Values for Base2Bytes.

func (Base2Bytes) Num

func (b Base2Bytes) Num(value int64) float64

func (Base2Bytes) Standardize

func (b Base2Bytes) Standardize() (float64, string)

type Block

type Block struct {
	// contains filtered or unexported fields
}

func (Block) Calculate

func (s Block) Calculate(_, blocks int64) int64

func (Block) String

func (s Block) String() string

type Calculator

type Calculator interface {
	Calculate(bytes, blocks int64) int64
	String() string
}

Calculator is used to calculate the size of a file or directory based on either its size in bytes (often referred to as its apparent size) and/or the number of storage blocks it occupies. Some file systems support sparse files (most unix filesystems) where the number of blocks occupied by a file is less than the number of bytes it represents, hence, the term 'apparent size'.

func NewBlock

func NewBlock(blocksize int64) Calculator

Block uses the number of blocks occupied by a file to calculate its size.

func NewIdentity

func NewIdentity() Calculator

func NewRAID0

func NewRAID0(stripeSize int64, numStripes int) Calculator

func NewRoundup

func NewRoundup(blocksize int64) Calculator

type DecimalBytes

type DecimalBytes int64

Base2Bytes represents a number of bytes in base 10.

Example
package main

import (
	"fmt"

	"cloudeng.io/file/diskusage"
)

func main() {
	fmt.Println(diskusage.KB.Num(500))
	fmt.Println(diskusage.KB.Num(2000))
	fmt.Println(diskusage.GB.Num(1000000000))
	fmt.Println(diskusage.DecimalBytes(1000).Standardize())
	fmt.Println(diskusage.DecimalBytes(1500).Standardize())
	fmt.Println(diskusage.DecimalBytes(1500000000).Standardize())
}
Output:

0.5
2
1
1 KB
1.5 KB
1.5 GB
const (
	KB DecimalBytes = 1000
	MB DecimalBytes = KB * 1000
	GB DecimalBytes = MB * 1000
	TB DecimalBytes = GB * 1000
	PB DecimalBytes = TB * 1000
	EB DecimalBytes = PB * 1000
)

Values for DecimalBytes.

func (DecimalBytes) Num

func (b DecimalBytes) Num(value int64) float64

func (DecimalBytes) Standardize

func (b DecimalBytes) Standardize() (float64, string)

type Identity

type Identity struct{}

Identity returns the apparent size of a file.

func (Identity) Calculate

func (i Identity) Calculate(bytes, _ int64) int64

func (Identity) String

func (i Identity) String() string

type RAID0

type RAID0 struct {
	// contains filtered or unexported fields
}

RAID0 is a calculator for RAID0 volumes based on the apparent size of the file and the RAID0 stripe size and number of stripes.

func (RAID0) Calculate

func (r0 RAID0) Calculate(size, _ int64) int64

func (RAID0) String

func (r0 RAID0) String() string

type Roundup

type Roundup struct {
	// contains filtered or unexported fields
}

Roundup rounds up the apparent size of a file to the nearest block size multiple.

func (Roundup) Calculate

func (s Roundup) Calculate(bytes, _ int64) int64

func (Roundup) String

func (s Roundup) String() string

Jump to

Keyboard shortcuts

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