1 Star 0 Fork 1

freely随意/BaiduPCS-Go

forked from ttpc2008/BaiduPCS-Go 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
instance_state.go 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
konica 提交于 2018-08-04 22:27 . 更新错误处理, 增加搜索文件
package uploader
import (
"io"
)
type (
// BlockState 文件区块信息
BlockState struct {
ID int `json:"id"`
Range ReadRange `json:"range"`
CheckSum string `json:"checksum"`
}
// InstanceState 上传断点续传信息
InstanceState struct {
BlockList []*BlockState `json:"block_list"`
}
)
func workerListToInstanceState(workers workerList) *InstanceState {
blockStates := make([]*BlockState, 0, len(workers))
for _, wer := range workers {
blockStates = append(blockStates, &BlockState{
ID: wer.id,
Range: wer.splitUnit.Range(),
CheckSum: wer.checksum,
})
}
return &InstanceState{
BlockList: blockStates,
}
}
func instanceStateToWorkerList(is *InstanceState, file io.ReaderAt) 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: NewSplitUnit(file, blockState.Range),
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: file,
},
checksum: blockState.CheckSum,
})
}
}
return workers
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/freelysuiyi/BaiduPCS-Go.git
git@gitee.com:freelysuiyi/BaiduPCS-Go.git
freelysuiyi
BaiduPCS-Go
BaiduPCS-Go
v3.5.6

搜索帮助