pkg/units: Unit constants directly int64
int64 seems sufficient Docker-DCO-1.1-Signed-off-by: Francisco Carriedo <fcarriedo@gmail.com> (github: fcarriedo)
This commit is contained in:
parent
16fedac8f0
commit
804ea3b58e
1 changed files with 12 additions and 14 deletions
|
@ -7,26 +7,24 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type unit int64
|
|
||||||
|
|
||||||
// See: http://en.wikipedia.org/wiki/Binary_prefix
|
// See: http://en.wikipedia.org/wiki/Binary_prefix
|
||||||
const (
|
const (
|
||||||
// Decimal
|
// Decimal
|
||||||
KB unit = 1000
|
KB = 1000
|
||||||
MB = 1000 * KB
|
MB = 1000 * KB
|
||||||
GB = 1000 * MB
|
GB = 1000 * MB
|
||||||
TB = 1000 * GB
|
TB = 1000 * GB
|
||||||
PB = 1000 * TB
|
PB = 1000 * TB
|
||||||
|
|
||||||
// Binary
|
// Binary
|
||||||
KiB unit = 1024
|
KiB = 1024
|
||||||
MiB = 1024 * KiB
|
MiB = 1024 * KiB
|
||||||
GiB = 1024 * MiB
|
GiB = 1024 * MiB
|
||||||
TiB = 1024 * GiB
|
TiB = 1024 * GiB
|
||||||
PiB = 1024 * TiB
|
PiB = 1024 * TiB
|
||||||
)
|
)
|
||||||
|
|
||||||
type unitMap map[string]unit
|
type unitMap map[string]int64
|
||||||
|
|
||||||
var (
|
var (
|
||||||
decimalMap = unitMap{"k": KB, "m": MB, "g": GB, "t": TB, "p": PB}
|
decimalMap = unitMap{"k": KB, "m": MB, "g": GB, "t": TB, "p": PB}
|
||||||
|
@ -81,7 +79,7 @@ func parseSize(sizeStr string, uMap unitMap) (int64, error) {
|
||||||
|
|
||||||
unitPrefix := strings.ToLower(matches[2])
|
unitPrefix := strings.ToLower(matches[2])
|
||||||
if mul, ok := uMap[unitPrefix]; ok {
|
if mul, ok := uMap[unitPrefix]; ok {
|
||||||
size *= int64(mul)
|
size *= mul
|
||||||
}
|
}
|
||||||
|
|
||||||
return size, nil
|
return size, nil
|
||||||
|
|
Loading…
Reference in a new issue