forked from qjfoidnh/BaiduPCS-Go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
instance_state.go
46 lines (42 loc) · 1.22 KB
/
instance_state.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
42
43
44
45
46
package uploader
import (
"github.com/qjfoidnh/BaiduPCS-Go/requester/transfer"
)
type (
// BlockState 文件区块信息
BlockState struct {
ID int `json:"id"`
Range transfer.Range `json:"range"`
CheckSum string `json:"checksum"`
}
// InstanceState 上传断点续传信息
InstanceState struct {
BlockList []*BlockState `json:"block_list"`
}
)
func (muer *MultiUploader) getWorkerListByInstanceState(is *InstanceState) workerList {
workers := make(workerList, 0, len(is.BlockList))
for _, blockState := range is.BlockList {
if blockState.CheckSum == "" {
workers = append(workers, &worker{
id: blockState.ID,
partOffset: blockState.Range.Begin,
splitUnit: NewBufioSplitUnit(muer.file, blockState.Range, muer.speedsStat, muer.rateLimit),
checksum: blockState.CheckSum,
})
} else {
// 已经完成的, 也要加入 (可继续优化)
workers = append(workers, &worker{
id: blockState.ID,
partOffset: blockState.Range.Begin,
splitUnit: &fileBlock{
readRange: blockState.Range,
readed: blockState.Range.End - blockState.Range.Begin,
readerAt: muer.file,
},
checksum: blockState.CheckSum,
})
}
}
return workers
}