aboutsummaryrefslogtreecommitdiff
path: root/steam/formatBytes.go
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2021-01-08 23:03:01 -0500
committerMitch Riedstra <mitch@riedstra.us>2021-01-08 23:03:32 -0500
commitd762cdbae06efd194ffac7b976c16aac21a26f94 (patch)
tree91372f7cb8118dea56255d0f35294574df339ed0 /steam/formatBytes.go
parent11c0e0ca37ce58d74f3cd5831265b9912f6bc8ea (diff)
downloadsteam-export-d762cdbae06efd194ffac7b976c16aac21a26f94.tar.gz
steam-export-d762cdbae06efd194ffac7b976c16aac21a26f94.tar.xz
Also show the size of games on the page listing
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
+}