Skip to content

Commit

Permalink
Show progress of downloads
Browse files Browse the repository at this point in the history
Fix buildpacks#236

Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Sep 13, 2019
1 parent 889dfa4 commit 56420fe
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 1 deletion.
19 changes: 18 additions & 1 deletion blob/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path/filepath"

"github.com/mitchellh/ioprogress"
"github.com/pkg/errors"

"github.com/buildpack/pack/internal/paths"
Expand Down Expand Up @@ -143,7 +144,7 @@ func (d *downloader) downloadAsStream(ctx context.Context, uri string, etag stri

if resp.StatusCode >= 200 && resp.StatusCode < 300 {
d.logger.Debugf("Downloading from %s", style.Symbol(uri))
return resp.Body, resp.Header.Get("Etag"), nil
return withProgress(resp.Body, resp.ContentLength), resp.Header.Get("Etag"), nil
}

if resp.StatusCode == 304 {
Expand All @@ -157,6 +158,22 @@ func (d *downloader) downloadAsStream(ctx context.Context, uri string, etag stri
)
}

func withProgress(rc io.ReadCloser, length int64) io.ReadCloser {
return &progressReader{
Closer: rc,
Reader: &ioprogress.Reader{
Reader: rc,
Size: length,
DrawFunc: ioprogress.DrawTerminalf(os.Stdout, ioprogress.DrawTextFormatBytes),
},
}
}

type progressReader struct {
*ioprogress.Reader
io.Closer
}

func (d *downloader) versionedCacheDir() string {
return filepath.Join(d.baseCacheDir, cacheDirPrefix+cacheVersion)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e
github.com/onsi/gomega v1.5.0
github.com/pkg/errors v0.8.1
github.com/sclevine/spec v1.2.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRU
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e h1:Qa6dnn8DlasdXRnacluu8HzPts0S1I9zvvUPDbBnXFI=
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e/go.mod h1:waEya8ee1Ro/lgxpVhkJI4BVASzkm3UZqkx/cFJiYHM=
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8dQu6DMTwH4oIuGN8GJDAlqDdVE=
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/mitchellh/ioprogress/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions vendor/github.com/mitchellh/ioprogress/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions vendor/github.com/mitchellh/ioprogress/draw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 107 additions & 0 deletions vendor/github.com/mitchellh/ioprogress/reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ github.com/konsorten/go-windows-terminal-sequences
github.com/mattn/go-colorable
# github.com/mattn/go-isatty v0.0.4
github.com/mattn/go-isatty
# github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e
github.com/mitchellh/ioprogress
# github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c
github.com/morikuni/aec
# github.com/onsi/gomega v1.5.0
Expand Down

0 comments on commit 56420fe

Please sign in to comment.