-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance for upload and download. Improve progress bar.
- Loading branch information
1 parent
8f4bb32
commit 1868a00
Showing
2 changed files
with
113 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
progressbar "gopkg.in/cheggaaa/pb.v1" | ||
"io" | ||
) | ||
|
||
type Bar struct { | ||
pb *progressbar.ProgressBar | ||
show bool | ||
} | ||
|
||
func StartNewByteBar(show bool, total int64) *Bar { | ||
if show { | ||
return &Bar{ | ||
show: true, | ||
pb: progressbar.StartNew(int(total)).SetUnits(progressbar.U_BYTES), | ||
} | ||
} | ||
return &Bar{ | ||
show: false, | ||
} | ||
} | ||
|
||
func StartNewBar(show bool, total int) *Bar { | ||
if show { | ||
return &Bar{ | ||
show: true, | ||
pb: progressbar.StartNew(total), | ||
} | ||
} | ||
return &Bar{ | ||
show: false, | ||
} | ||
} | ||
|
||
func (b *Bar) FinishPrint(str string) { | ||
if b.show { | ||
b.pb.FinishPrint(str) | ||
} | ||
} | ||
|
||
func (b *Bar) Add64(add int64) { | ||
if b.show { | ||
b.pb.Add64(add) | ||
} | ||
} | ||
|
||
func (b *Bar) Set(current int) { | ||
if b.show { | ||
b.pb.Set(current) | ||
} | ||
} | ||
|
||
func (b *Bar) Increment() { | ||
if b.show { | ||
b.pb.Increment() | ||
} | ||
} | ||
|
||
func (b *Bar) NewProxyReader(r io.Reader) io.Reader { | ||
if b.show { | ||
return b.pb.NewProxyReader(r) | ||
} | ||
return r | ||
} |
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