ea60d1a6148c — Dang Hoang Tuan (Tsuki) 2 years ago
Uses IEC instead of SI for human-readable file size format to fit with Linux
1 files changed, 5 insertions(+), 5 deletions(-)

M helper_functions.go
M helper_functions.go +5 -5
@@ 36,10 36,10 @@ func notFound(c echo.Context, msg string
 	return c.String(NOT_FOUND, msg)
 }
 
-// Formatting byte size in human-readable format (SI - decimal)
+// Formatting byte size in human-readable format (IEC/binary)
 // From https://yourbasic.org/golang/formatting-byte-size-to-human-readable-format/
-func ByteCountSI(b int64) string {
-    const unit = 1000
+func ByteCountIEC(b int64) string {
+    const unit = 1024
     if b < unit {
         return fmt.Sprintf("%d B", b)
     }

          
@@ 48,6 48,6 @@ func ByteCountSI(b int64) string {
         div *= unit
         exp++
     }
-    return fmt.Sprintf("%.1f %cB",
-        float64(b)/float64(div), "kMGTPE"[exp])
+    return fmt.Sprintf("%.1f %ciB",
+        float64(b)/float64(div), "KMGTPE"[exp])
 }