-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #929 from Tinyblargon/Fix#912
[3.0.1-rc1] Feature: KMGT disk size
- Loading branch information
Showing
6 changed files
with
114 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package proxmox | ||
|
||
import ( | ||
"strconv" | ||
) | ||
|
||
const ( | ||
kibibyte int64 = 1 | ||
mebibyte int64 = 1024 | ||
gibibyte int64 = 1048576 | ||
tebibyte int64 = 1073741824 | ||
) | ||
|
||
func convert_KibibytesToString(kibibytes int64) string { | ||
if kibibytes%tebibyte == 0 { | ||
return strconv.FormatInt(kibibytes/tebibyte, 10) + "T" | ||
} | ||
if kibibytes%gibibyte == 0 { | ||
return strconv.FormatInt(kibibytes/gibibyte, 10) + "G" | ||
} | ||
if kibibytes%mebibyte == 0 { | ||
return strconv.FormatInt(kibibytes/mebibyte, 10) + "M" | ||
} | ||
return strconv.FormatInt(kibibytes, 10) + "K" | ||
} | ||
|
||
// Relies on the input being validated | ||
func convert_SizeStringToKibibytes_Unsafe(size string) int { | ||
if len(size) > 1 { | ||
switch size[len(size)-1:] { | ||
case "T": | ||
return parseSize_Unsafe(size, tebibyte) | ||
case "G": | ||
return parseSize_Unsafe(size, gibibyte) | ||
case "M": | ||
return parseSize_Unsafe(size, mebibyte) | ||
case "K": | ||
return parseSize_Unsafe(size, kibibyte) | ||
} | ||
} | ||
tmpSize, _ := strconv.ParseInt(size, 10, 0) | ||
return int(tmpSize * gibibyte) | ||
} | ||
|
||
// Relies on the input being validated | ||
func parseSize_Unsafe(size string, multiplier int64) int { | ||
tmpSize, _ := strconv.ParseInt(size[:len(size)-1], 10, 0) | ||
return int(tmpSize * multiplier) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters