common: define storage units as constants
Define all used storage units as constants. Use them in `DataSizeToUint64()`, instead of literal multiples.
This commit is contained in:
parent
b5d1c8866a
commit
ff28b0f5d3
2 changed files with 19 additions and 8 deletions
|
|
@ -2,6 +2,17 @@ package common
|
|||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
KiloByte = 1000 // kB
|
||||
KibiByte = 1024 // KiB
|
||||
MegaByte = 1000 * 1000 // MB
|
||||
MebiByte = 1024 * 1024 // MiB
|
||||
GigaByte = 1000 * 1000 * 1000 // GB
|
||||
GibiByte = 1024 * 1024 * 1024 // GiB
|
||||
TeraByte = 1000 * 1000 * 1000 * 1000 // TB
|
||||
TebiByte = 1024 * 1024 * 1024 * 1024 // TiB
|
||||
)
|
||||
|
||||
// These constants are set during buildtime using additional
|
||||
// compiler flags. Not all of them are necessarily defined
|
||||
// because RPMs can be build from a tarball and spec file without
|
||||
|
|
|
|||
|
|
@ -65,14 +65,14 @@ func DataSizeToUint64(size string) (uint64, error) {
|
|||
re *regexp.Regexp
|
||||
multiple uint64
|
||||
}{
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*kB$`), 1000},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*KiB$`), 1024},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*MB$`), 1000 * 1000},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*MiB$`), 1024 * 1024},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*GB$`), 1000 * 1000 * 1000},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*GiB$`), 1024 * 1024 * 1024},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*TB$`), 1000 * 1000 * 1000 * 1000},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*TiB$`), 1024 * 1024 * 1024 * 1024},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*kB$`), KiloByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*KiB$`), KibiByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*MB$`), MegaByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*MiB$`), MebiByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*GB$`), GigaByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*GiB$`), GibiByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*TB$`), TeraByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+\s*TiB$`), TebiByte},
|
||||
{regexp.MustCompile(`^\s*[[:digit:]]+$`), 1},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue