Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/oras/internal/display/status/progress/humanize/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

const base = 1024.0

var units = []string{"B", "kB", "MB", "GB", "TB"}
var units = []string{"B", "KB", "MB", "GB", "TB"}

type Bytes struct {
Size float64
Expand All @@ -46,7 +46,7 @@ func ToBytes(sizeInBytes int64) Bytes {

// String returns the string representation of Bytes.
func (b Bytes) String() string {
return fmt.Sprintf("%v %2s", b.Size, b.Unit)
return fmt.Sprintf("%g %2s", b.Size, b.Unit)
}

// RoundTo makes length of the size string to less than or equal to 4.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func TestToBytes(t *testing.T) {
}{
{"0 bytes", args{0}, Bytes{0, "B"}},
{"1023 bytes", args{1023}, Bytes{1023, "B"}},
{"1 kB", args{1024}, Bytes{1, "kB"}},
{"1.5 kB", args{1024 + 512}, Bytes{1.5, "kB"}},
{"12.5 kB", args{1024 * 12.5}, Bytes{12.5, "kB"}},
{"512.5 kB", args{1024 * 512.5}, Bytes{513, "kB"}},
{"1 KB", args{1024}, Bytes{1, "KB"}},
{"1.5 KB", args{1024 + 512}, Bytes{1.5, "KB"}},
{"12.5 KB", args{1024 * 12.5}, Bytes{12.5, "KB"}},
{"512.5 KB", args{1024 * 512.5}, Bytes{513, "KB"}},
{"1 MB", args{1024 * 1024}, Bytes{1, "MB"}},
{"1 GB", args{1024 * 1024 * 1024}, Bytes{1, "GB"}},
{"1 TB", args{1024 * 1024 * 1024 * 1024}, Bytes{1, "TB"}},
Expand Down
Loading