forked from Angey40/BaiduPCS-Go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.go
41 lines (34 loc) · 811 Bytes
/
example.go
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
package uploader
import (
"fmt"
"github.com/iikira/BaiduPCS-Go/pcsutil/converter"
"github.com/iikira/BaiduPCS-Go/requester/rio"
)
// DoUpload 执行上传
func DoUpload(uploadURL string, readerlen64 rio.ReaderLen64, checkFunc CheckFunc) {
u := NewUploader(uploadURL, readerlen64)
u.SetCheckFunc(checkFunc)
exitChan := make(chan struct{})
u.OnExecute(func() {
statusChan := u.GetStatusChan()
for {
select {
case <-exitChan:
return
case v, ok := <-statusChan:
if !ok {
return
}
fmt.Printf("\r ↑ %s/%s %s/s in %s ............",
converter.ConvertFileSize(v.Uploaded(), 2),
converter.ConvertFileSize(v.TotalSize(), 2),
converter.ConvertFileSize(v.SpeedsPerSecond(), 2),
v.TimeElapsed(),
)
}
}
})
u.Execute()
close(exitChan)
return
}