aboutsummaryrefslogtreecommitdiff
path: root/steam/formatBytes.go
diff options
context:
space:
mode:
Diffstat (limited to 'steam/formatBytes.go')
-rw-r--r--steam/formatBytes.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/steam/formatBytes.go b/steam/formatBytes.go
new file mode 100644
index 0000000..8627b58
--- /dev/null
+++ b/steam/formatBytes.go
@@ -0,0 +1,28 @@
+package steam
+
+import (
+ "fmt"
+ "math"
+)
+
+func formatBytes(b int64) string {
+ if b < 1024 {
+ return fmt.Sprintf("%d b", b)
+ }
+
+ s := ""
+
+ pfxs := "kmgt"
+ for i := 0; i < len(pfxs); i++ {
+ pow := math.Pow(float64(1024), float64(i+1))
+ // This one is too big, return the previous string
+ if b < int64(pow) {
+ return s
+ }
+ s = fmt.Sprintf("%.2f %cb",
+ float64(b)/(pow),
+ pfxs[i])
+ }
+
+ return s
+}