mirror of
https://github.com/coalaura/up.git
synced 2025-07-17 21:44:35 +00:00
msgpack and streaming
This commit is contained in:
35
client/progress.go
Normal file
35
client/progress.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/coalaura/progress"
|
||||
)
|
||||
|
||||
type ProgressReader struct {
|
||||
io.Reader
|
||||
bar *progress.Bar
|
||||
}
|
||||
|
||||
func NewProgressReader(label string, total int64, reader io.Reader) *ProgressReader {
|
||||
bar := progress.NewProgressBarWithTheme(label, total, progress.ThemeDots)
|
||||
|
||||
bar.Start()
|
||||
|
||||
return &ProgressReader{
|
||||
Reader: reader,
|
||||
bar: bar,
|
||||
}
|
||||
}
|
||||
|
||||
func (pr *ProgressReader) Read(p []byte) (int, error) {
|
||||
n, err := pr.Reader.Read(p)
|
||||
|
||||
pr.bar.IncrementBy(int64(n))
|
||||
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (pr *ProgressReader) Close() {
|
||||
pr.bar.Stop()
|
||||
}
|
Reference in New Issue
Block a user