From d735cca9706ddbf2027f6b5e01812f33cc42a84f Mon Sep 17 00:00:00 2001 From: Marcus Date: Mon, 7 Dec 2020 18:44:12 -0600 Subject: [PATCH] Issue #306, File Size Mismatch Updated utils.go to use a `1024` grouping instead of `1000` for file sizes. This brings it inline with the progress bar project being used. Updated utils_test.go to match the changes to utils.go --- src/utils/utils.go | 2 +- src/utils/utils_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/utils.go b/src/utils/utils.go index 9e4bc49..cc74bf6 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -136,7 +136,7 @@ func GetRandomName() string { // ByteCountDecimal converts bytes to human readable byte string func ByteCountDecimal(b int64) string { - const unit = 1000 + const unit = 1024 if b < unit { return fmt.Sprintf("%d B", b) } diff --git a/src/utils/utils_test.go b/src/utils/utils_test.go index 101162e..8e3acaa 100644 --- a/src/utils/utils_test.go +++ b/src/utils/utils_test.go @@ -88,9 +88,9 @@ func TestSHA256(t *testing.T) { } func TestByteCountDecimal(t *testing.T) { - assert.Equal(t, "10.0 kB", ByteCountDecimal(10000)) + assert.Equal(t, "10.0 kB", ByteCountDecimal(10240)) assert.Equal(t, "50 B", ByteCountDecimal(50)) - assert.Equal(t, "12.4 MB", ByteCountDecimal(12378517)) + assert.Equal(t, "12.4 MB", ByteCountDecimal(13002343)) } func TestMissingChunks(t *testing.T) {