From b15a0fd906f154a35a19f3da3de818cf327f5eea Mon Sep 17 00:00:00 2001 From: Arnaud Rebillout Date: Wed, 4 Feb 2026 22:33:50 +0700 Subject: [PATCH] Use IEC prefixes for file sizes This to clear any confusion around file size. As reported at #205, some OS, or desktop environments, or applications, or whatever, show file sizes using SI units (ie. multiples of 1000), while others use IEC units (multiples of 1024). And both might use the suffixes KB, MB, GB and TB for it. So users get confused. For example, a file that is said to be "3.5 GB" in the Mirrorbits page, will then appear as "3.8 GB" after download in the GNOME file manager, because GNOME prefers SI units. So let's use the IEC prefixes (Ki, Mi, Gi and Ti) in the Mirrorbits web pages, that should clear any ambiguity. Closes: #205 --- utils/utils.go | 4 ++-- utils/utils_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 8c1cfaee..50a06089 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -104,12 +104,12 @@ func IsStopped(stop <-chan struct{}) bool { // ReadableSize returns a file size in a human readable form func ReadableSize(value int64) string { - units := []string{"bytes", "KB", "MB", "GB", "TB"} + units := []string{"bytes", "KiB", "MiB", "GiB", "TiB"} v := float64(value) for _, u := range units { - if v < 1024 || u == "TB" { + if v < 1024 || u == "TiB" { return fmt.Sprintf("%3.1f %s", v, u) } v /= 1024 diff --git a/utils/utils_test.go b/utils/utils_test.go index 05a1af3c..653adeea 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -118,7 +118,7 @@ func TestIsStopped(t *testing.T) { func TestReadableSize(t *testing.T) { ivalues := []int64{0, 1, 1024, 1000000} - svalues := []string{"0.0 bytes", "1.0 bytes", "1.0 KB", "976.6 KB"} + svalues := []string{"0.0 bytes", "1.0 bytes", "1.0 KiB", "976.6 KiB"} for i := range ivalues { if r := ReadableSize(ivalues[i]); r != svalues[i] {