# HG changeset patch # User Dang Hoang Tuan (Tsuki) # Date 1657699508 -25200 # Wed Jul 13 15:05:08 2022 +0700 # Node ID ea60d1a6148c20450f9b846d08897eb692a38a64 # Parent a9cf21a3a0970cfa529d525269671b8386eb684f Uses IEC instead of SI for human-readable file size format to fit with Linux diff --git a/helper_functions.go b/helper_functions.go --- a/helper_functions.go +++ b/helper_functions.go @@ -36,10 +36,10 @@ 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 @@ 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]) }