Skip to content

Commit

Permalink
Merge pull request imroc#43 from maddie/last-progress
Browse files Browse the repository at this point in the history
Report progress on upload and download finish
  • Loading branch information
imroc authored Aug 26, 2019
2 parents fc8e479 + ba3ab25 commit e3a4bfb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions req.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@ func (m *multipartHelper) Upload(req *http.Request) {
var current int64
buf := make([]byte, 1024)
var lastTime time.Time

defer func() {
m.uploadProgress(current, total)
}()

upload = func(w io.Writer, r io.Reader) error {
for {
n, err := r.Read(buf)
Expand Down
5 changes: 5 additions & 0 deletions resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ func (r *Resp) download(file *os.File) error {
total := r.resp.ContentLength
var current int64
var lastTime time.Time

defer func() {
r.downloadProgress(current, total)
}()

for {
l, err := b.Read(p)
if l > 0 {
Expand Down

0 comments on commit e3a4bfb

Please sign in to comment.