github.com/fraugster/parquet-go@v0.12.0/cmd/parquet-tool/cmds/helpers.go (about) 1 package cmds 2 3 import ( 4 "fmt" 5 "strconv" 6 "strings" 7 ) 8 9 var acceptableSuffix = map[string]int64{ 10 "KB": 1024, 11 "KiB": 1000, 12 "MB": 1024 * 1024, 13 "MiB": 1000 * 1000, 14 "GB": 1024 * 1024 * 1024, 15 "GiB": 1000 * 1000 * 1000, 16 "TB": 1024 * 1024 * 1024 * 1024, 17 "TiB": 1000 * 1000 * 1000 * 1000, 18 "PB": 1024 * 1024 * 1024 * 1024 * 1024, 19 "PiB": 1000 * 1000 * 1000 * 1000 * 1000, 20 } 21 22 func humanToByte(in string) (int64, error) { 23 in = strings.Trim(in, " \n\t") 24 if b, err := strconv.ParseInt(in, 10, 0); err == nil { 25 return b, nil 26 } 27 28 for i := range acceptableSuffix { 29 if strings.HasSuffix(in, i) { 30 in = strings.TrimSuffix(in, i) 31 b, err := strconv.ParseInt(in, 10, 0) 32 if err != nil { 33 return 0, err 34 } 35 return b * acceptableSuffix[i], nil 36 } 37 } 38 39 return 0, fmt.Errorf("invalid format") 40 }