MCPcopy Create free account
hub / github.com/MertJSX/folderhost / ConvertStringToBytes

Function ConvertStringToBytes

utils/convert_string_to_bytes.go:10–29  ·  view source on GitHub ↗

Missing possible error handlings... But still should work...

(size string)

Source from the content-addressed store, hash-verified

8
9// Missing possible error handlings... But still should work...
10func ConvertStringToBytes(size string) int64 {
11 sizes := []string{"Bytes", "KB", "MB", "GB", "TB"}
12
13 parts := strings.Split(size, " ")
14 value, err := strconv.ParseFloat(parts[0], 64)
15
16 if err != nil {
17 return 0
18 }
19
20 var unit string = parts[1]
21 var index int = IndexOf(unit, sizes)
22
23 if index == -1 {
24 return 0
25 }
26
27 return int64(value * math.Pow(1024, float64(index)))
28
29}

Callers 3

LoadConfigMethod · 0.92
DeleteFunction · 0.92
GetConfigFunction · 0.85

Calls 1

IndexOfFunction · 0.85

Tested by

no test coverage detected