Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide callback progress hooks for long copies.
Signed-off-by: Erik Hollensbe <github@hollensbe.org>
- Loading branch information
Erik Hollensbe
committed
Feb 23, 2017
1 parent
3ff6510
commit ac3f354
Showing
3 changed files
with
62 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package copy | ||
|
||
import ( | ||
"io" | ||
"time" | ||
|
||
"github.com/containers/image/types" | ||
) | ||
|
||
// progressReader is a reader that reports its progress on an interval. | ||
type progressReader struct { | ||
source io.Reader | ||
channel chan types.ProgressProperties | ||
interval time.Duration | ||
artifact types.BlobInfo | ||
lastTime time.Time | ||
offset uint64 | ||
} | ||
|
||
func (r *progressReader) Read(p []byte) (int, error) { | ||
n, err := r.source.Read(p) | ||
r.offset += uint64(n) | ||
if time.Since(r.lastTime) > r.interval { | ||
r.channel <- types.ProgressProperties{Artifact: r.artifact, Offset: r.offset} | ||
r.lastTime = time.Now() | ||
} | ||
return n, err | ||
} |
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