forked from hashicorp/go-getter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow to track download progress by passing options
Also set default Getters, Decompressors & Detectors in Configure func with the idea to add a validate func that will validate if src url will work in the future
- Loading branch information
Showing
12 changed files
with
164 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package getter | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
// WithProgress allows for a user to track | ||
// the progress of a download. | ||
// For example by displaying a progress bar with | ||
// current download. | ||
// Not all getters have progress support yet. | ||
func WithProgress(pl ProgressTracker) func(*Client) error { | ||
return func(c *Client) error { | ||
c.ProgressListener = pl | ||
return nil | ||
} | ||
} | ||
|
||
// ProgressTracker allows to track the progress of downloads. | ||
type ProgressTracker interface { | ||
// TrackProgress should be called when | ||
// a new object is being downloaded. | ||
// src is the location the file is | ||
// downloaded from. | ||
// size is the total size in bytes, | ||
// size can be zero if the file size | ||
// is not known. | ||
// stream is the file being downloaded, every | ||
// written byte will add up to processed size. | ||
// | ||
// TrackProgress returns a ReadCloser that wraps the | ||
// download in progress ( stream ). | ||
// When the download is finished, body shall be closed. | ||
TrackProgress(src string, size int64, stream io.ReadCloser) (body io.ReadCloser) | ||
} | ||
|
||
// NoopProgressListener is a progress listener | ||
// that has no effect. | ||
type NoopProgressListener struct{} | ||
|
||
var noopProgressListener ProgressTracker = &NoopProgressListener{} | ||
|
||
// TrackProgress is a no op | ||
func (*NoopProgressListener) TrackProgress(_ string, _ int64, stream io.ReadCloser) io.ReadCloser { | ||
return stream | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package getter | ||
|
||
// getter is our base getter; it regroups | ||
// fields all getters have in common. | ||
type getter struct { | ||
client *Client | ||
} | ||
|
||
func (g *getter) SetClient(c *Client) { g.client = c } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters