diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2021-01-09 15:22:27 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2021-01-09 15:22:27 -0500 |
| commit | 602790e2ca33ad7f22235bf2ae548cef7db8b814 (patch) | |
| tree | f79fc9a7f6e019a3f2a774e13d030937b3ae9f86 /cmd/web/formatBytes.go | |
| parent | e31c9168627c040317e5cc8566724f88910439ae (diff) | |
| download | steam-export-602790e2ca33ad7f22235bf2ae548cef7db8b814.tar.gz steam-export-602790e2ca33ad7f22235bf2ae548cef7db8b814.tar.xz | |
Add a progress bar to the UI for installation via HTTP. Uses polling, but whatever.
Diffstat (limited to 'cmd/web/formatBytes.go')
| -rw-r--r-- | cmd/web/formatBytes.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cmd/web/formatBytes.go b/cmd/web/formatBytes.go new file mode 100644 index 0000000..d5d2aab --- /dev/null +++ b/cmd/web/formatBytes.go @@ -0,0 +1,29 @@ +package main + +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 +} + |
