summaryrefslogtreecommitdiff
path: root/bytes.go
diff options
context:
space:
mode:
Diffstat (limited to 'bytes.go')
-rw-r--r--bytes.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/bytes.go b/bytes.go
new file mode 100644
index 0000000..7b40804
--- /dev/null
+++ b/bytes.go
@@ -0,0 +1,47 @@
+package cobol
+
+import (
+ "fmt"
+)
+
+// returns a human readable string of the bytes
+func Bytes(anInt any) string {
+ return "todo"
+}
+
+// returns a human readable string of the bytes
+// also returns the error if there was one
+func BytesCheck(anInt any) (string, error) {
+ return "todo", NoBytes
+}
+
+// returns an int. will try to convert strings
+func GetBytes(anInt any) (int, error) {
+ return 0, NoBytes
+}
+
+// This isn't for the marketing department
+// so this isn't going to use 'MiB' and 'GiB'
+func HumanFormatBytes(b int) string {
+ if b < 2000 {
+ return fmt.Sprintf("%d B", b)
+ }
+
+ kb := int(b / 1024)
+ if kb < 2000 {
+ return fmt.Sprintf("%d KB", kb)
+ }
+
+ mb := int(b / (1024 * 1024))
+ if mb < 2000 {
+ return fmt.Sprintf("%d MB", mb)
+ }
+
+ gb := int(b / (1024 * 1024 * 1024))
+ if gb < 2000 {
+ return fmt.Sprintf("%d GB", gb)
+ }
+
+ tb := int(b / (1024 * 1024 * 1024 * 1024))
+ return fmt.Sprintf("%d TB", tb)
+}