-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (46 loc) · 969 Bytes
/
main.go
File metadata and controls
57 lines (46 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"crypto/rand"
"io"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
const size = 32
func main() {
var total int64 = size * 1024 * 1024
r, w := io.Pipe()
go func() {
for range 1024 {
_, err := io.Copy(w, io.LimitReader(rand.Reader, size*1024))
if err != nil {
panic(err)
}
time.Sleep(time.Second / 10)
}
_ = w.Close()
}()
p := mpb.New(mpb.WithWidth(60))
bar := p.New(total,
mpb.BarStyle().Rbound("|"),
mpb.PrependDecorators(
decor.Counters(decor.SizeB1024(0), "% .2f / % .2f"),
),
mpb.AppendDecorators(
decor.EwmaETA(decor.ET_STYLE_GO, 30),
decor.Name(" ] "),
decor.EwmaSpeed(decor.SizeB1024(0), "% .2f", 30),
),
)
// create proxy reader
proxyReader := bar.ProxyReader(r)
defer func() {
_ = proxyReader.Close()
}()
// copy from proxyReader, ignoring errors
_, err := io.Copy(io.Discard, proxyReader)
if err != nil {
panic(err)
}
p.Wait()
}