Skip to content

Commit 08ec721

Browse files
elboulangerojbkempf
authored andcommitted
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
1 parent 4125599 commit 08ec721

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

utils/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ func IsStopped(stop <-chan struct{}) bool {
104104

105105
// ReadableSize returns a file size in a human readable form
106106
func ReadableSize(value int64) string {
107-
units := []string{"bytes", "KB", "MB", "GB", "TB"}
107+
units := []string{"bytes", "KiB", "MiB", "GiB", "TiB"}
108108

109109
v := float64(value)
110110

111111
for _, u := range units {
112-
if v < 1024 || u == "TB" {
112+
if v < 1024 || u == "TiB" {
113113
return fmt.Sprintf("%3.1f %s", v, u)
114114
}
115115
v /= 1024

utils/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestIsStopped(t *testing.T) {
118118

119119
func TestReadableSize(t *testing.T) {
120120
ivalues := []int64{0, 1, 1024, 1000000}
121-
svalues := []string{"0.0 bytes", "1.0 bytes", "1.0 KB", "976.6 KB"}
121+
svalues := []string{"0.0 bytes", "1.0 bytes", "1.0 KiB", "976.6 KiB"}
122122

123123
for i := range ivalues {
124124
if r := ReadableSize(ivalues[i]); r != svalues[i] {

0 commit comments

Comments
 (0)