Documentation
¶
Index ¶
Examples ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func BinarySize ¶
func DecimalSize ¶
func ParseToBytes ¶
Types ¶
type Binary ¶
type Binary SizeUnit
Binary represents a number of bytes in base 2.
Example ¶
package main
import (
"fmt"
"cloudeng.io/file/diskusage"
)
func main() {
fmt.Println(diskusage.KiB.Value(512))
fmt.Println(diskusage.KiB.Value(2048))
fmt.Println(diskusage.GiB.Value(1073741824))
fmt.Println(diskusage.Binary(1024).Standardize())
fmt.Println(diskusage.Binary(1536).Standardize())
fmt.Println(diskusage.Binary(1610612736).Standardize())
fmt.Printf("%.0f\n", diskusage.Binary(512)) // Default precision
}
Output: 0.5 2 1 1 KiB 1.5 KiB 1.5 GiB 512 B
func (Binary) Standardize ¶
type Calculator ¶
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 Decimal ¶
type Decimal SizeUnit
Decimal represents a number of bytes in base 10.
Example ¶
package main
import (
"fmt"
"cloudeng.io/file/diskusage"
)
func main() {
fmt.Println(diskusage.KB.Value(500))
fmt.Println(diskusage.KB.Value(2000))
fmt.Println(diskusage.GB.Value(1000000000))
fmt.Println(diskusage.Decimal(1000).Standardize())
fmt.Println(diskusage.Decimal(1500).Standardize())
fmt.Println(diskusage.Decimal(1500000000).Standardize())
fmt.Printf("%.0f\n", diskusage.Decimal(500)) // Default precision
}
Output: 0.5 2 1 1 KB 1.5 KB 1.5 GB 500 B
func (Decimal) Standardize ¶
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.
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.
type SizeUnit ¶
type SizeUnit int64
SizeUnit represents a unit of size in bytes. It can be used to represent both decimal and binary sizes.