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 Oct 4, 2022
1 parent fe7deab commit e469fd5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/events",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/remote/util",
"//src/main/java/com/google/devtools/build/lib/util:os",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/net/starlark/java/syntax",
"//third_party:auth",
"//third_party:auto_value",
"//third_party:guava",
"//third_party:jsr305",
"//third_party:jsr305"
],
)
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 com.google.devtools.build.lib.remote.util.Utils;

/**
* 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)", Utils.bytesCountToDisplayString(bytesRead), bytesRead);
} else {
return "";
}
Expand Down

0 comments on commit e469fd5

Please sign in to comment.