# README
size
simple conversion between size and string
install
go get -u github.com/dstgo/size@latest
units
type Unit = int
const (
B Unit = 1 << (iota * 10)
KB
MB
GB
TB
PB
EB
)
usage
package main
import (
"fmt"
"github.com/dstgo/size"
)
func main() {
s1 := size.NewInt(1, size.KB)
fmt.Println(s1)
s2 := s1.To(size.MB)
fmt.Println(s2)
s3, ok := size.Lookup("1.2MB")
if !ok {
panic("failed to lookup")
}
fmt.Println(s3)
lookupTo, ok := size.LookupTo("1.2MB", size.KB)
if !ok {
panic("failed to lookup")
}
fmt.Println(lookupTo)
}
output
1KB
0.001MB
1.2MB
1228.8KB
# Functions
Lookup returns a new size from the given string, return false if parse failed, use B unit if str has no unit string.
LookupTo returns a new size from the given string that convert to given unit, return false if failed.
New returns a new size.
No description provided by the author
# Type aliases
No description provided by the author