diff --git a/module/util/file.go b/module/util/file.go index f11222b..83a7fbd 100644 --- a/module/util/file.go +++ b/module/util/file.go @@ -1,10 +1,14 @@ package util import ( + "math/big" + "github.com/dustin/go-humanize" ) // ByteCountBinary 把 Length 转换为文件大小, 自适应单位 func ByteCountBinary(b uint64) string { - return humanize.Bytes(b) + // uint64 to bigint + bigInt := new(big.Int).SetUint64(b) + return humanize.BigIBytes(bigInt) } diff --git a/module/util/file_test.go b/module/util/file_test.go index 60e18c6..2dbabe6 100644 --- a/module/util/file_test.go +++ b/module/util/file_test.go @@ -22,22 +22,22 @@ func TestByteCountBinary(t *testing.T) { { name: "KB", args: args{b: 1024}, - want: "1.0 kB", + want: "1.0 KiB", }, { name: "MB", args: args{b: 1024 * 1024 * 3}, - want: "3.1 MB", + want: "3.0 MiB", }, { name: "GB", args: args{b: 1024 * 1024 * 1024 * 3}, - want: "3.2 GB", + want: "3.0 GiB", }, { name: "TB", args: args{b: 1024 * 1024 * 1024 * 1024 * 3}, - want: "3.3 TB", + want: "3.0 TiB", }, } for _, tt := range tests {