Change file size units to IEC 80000-13:2025 (binary multiples) (#2062)

* Change file size units from SI to IEC 80000-13:2025

Increase left-padded (%S) file size string length to 5 characters

Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>

* Add note about used IEC units for file size in docs

---------

Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>
This commit is contained in:
Andrew VoynovandJoe Lim authored and GitHub committed 2025-07-26 19:03:13 +10:00
1 parent d60acef469
commit 23b30ae1ee
10 files changed
+90 -56

No files matched your search

+34 -18
View File
@@ -1,6 +1,7 @@
package main
import (
"math"
"os"
"reflect"
"strings"
@@ -247,29 +248,44 @@ func TestReadArrays(t *testing.T) {
func TestHumanize(t *testing.T) {
tests := []struct {
i int64
exp string
size uint64
expected string
}{
{0, "0B"},
{9, "9B"},
{99, "99B"},
{999, "999B"},
{1000, "1.0K"},
{1023, "1.0K"},
{1025, "1.0K"},
{1049, "1.0K"},
{1050, "1.0K"},
{1099, "1.0K"},
{9999, "9.9K"},
{10000, "10K"},
{10100, "10K"},
{10500, "10K"},
{1000000, "1.0M"},
{1, "1B"},
{2, "2B"},
{10, "10B"},
{100, "100B"},
{1000, "1000B"},
{1023, "1023B"},
{1024, "1.0K"},
{1025, "1.0K"}, // 1.000976563 KiB
{10188, "9.9K"}, // 9.94921875 KiB
{10189, "10.0K"}, // 9.950195313 KiB
{10240, "10.0K"}, // 10 KiB
{10291, "10.0K"}, // 10.049804688 KiB
{10292, "10.1K"}, // 10.05078125 KiB
{10342, "10.1K"}, // 10.099609375 KiB
{102348, "99.9K"}, // 99.94921875 KiB
{102349, "100K"}, // 99.950195313 KiB
{1023487, "999K"}, // 999.499023438 KiB
{1023488, "1000K"}, // 999.5 KiB
{1048063, "1023K"}, // 1023.499023438 KiB
{1048064, "1.0M"}, // 1023.5 KiB
{1072693248, "1023M"}, // 1023 MiB
{1073217535, "1023M"}, // 1023.499999046 MiB
{1073217536, "1.0G"}, // 1023.5 MiB
{1073741824, "1.0G"}, // 1 GiB
{1610612736, "1.5G"}, // 1.5 GiB
{1319413953332, "1.2T"}, // 1.2 TiB
{1463669878895412, "1.3P"}, // 1.3 PiB
{7955158381787244544, "6.9E"}, // 6.9 EiB
{math.MaxUint64, "16.0E"}, // 16 EiB
}
for _, test := range tests {
if got := humanize(test.i); got != test.exp {
t.Errorf("at input '%d' expected '%s' but got '%s'", test.i, test.exp, got)
if got := humanize(test.size); got != test.expected {
t.Errorf("at input '%d' expected '%s' but got '%s'", test.size, test.expected, got)
}
}
}