Skip to content

Commit

Permalink
Display human readable bytes in download progress
Browse files Browse the repository at this point in the history
Before:

```
Fetching https://mirror.bazel.build/..._x64.tar.gz; 28,324,614B 9s
```

After:

```
Fetching https://mirror.bazel.build/..._x64.tar.gz; 27 MB (28,324,614B) 9s
```
  • Loading branch information
blindpirate committed Aug 7, 2022
1 parent fe7deab commit 8589747
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ java_library(
"//third_party:auto_value",
"//third_party:guava",
"//third_party:jsr305",
"//third_party:apache_commons_io",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import com.google.devtools.build.lib.events.ExtendedEventHandler;
import java.net.URL;
import java.text.NumberFormat;
import java.util.Locale;
import org.apache.commons.io.FileUtils;

/**
* Postable event reporting on progress made downloading an URL. It can be used to report the URL
Expand Down Expand Up @@ -73,9 +73,7 @@ public long getBytesRead() {
@Override
public String getProgress() {
if (bytesRead > 0) {
NumberFormat formatter = NumberFormat.getIntegerInstance(Locale.ENGLISH);
formatter.setGroupingUsed(true);
return formatter.format(bytesRead) + "B";
return String.format("%s (%,dB)", FileUtils.byteCountToDisplaySize(bytesRead), bytesRead);
} else {
return "";
}
Expand Down

0 comments on commit 8589747

Please sign in to comment.