Documentation ¶
Overview ¶
Copyright (c) 2020 tickstep.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2020 tickstep.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2020 tickstep.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- type DownloadInstanceInfo
- type DownloadInstanceInfoExport
- type DownloadStatus
- func (ds *DownloadStatus) AddDownloaded(d int64)
- func (ds *DownloadStatus) AddSpeedsDownloaded(d int64)
- func (ds *DownloadStatus) AddTotalSize(size int64)
- func (ds *DownloadStatus) ClearMaxSpeeds()
- func (ds *DownloadStatus) Downloaded() int64
- func (ds *DownloadStatus) MaxSpeeds() int64
- func (ds *DownloadStatus) RangeListGen() *RangeListGen
- func (ds *DownloadStatus) SetMaxSpeeds(speeds int64)
- func (ds *DownloadStatus) SetRangeListGen(gen *RangeListGen)
- func (ds *DownloadStatus) SetRateLimit(rl *speeds.RateLimit)
- func (ds *DownloadStatus) SetTotalSize(size int64)
- func (ds *DownloadStatus) SpeedsPerSecond() int64
- func (ds *DownloadStatus) TimeElapsed() (elapsed time.Duration)
- func (ds *DownloadStatus) TimeLeft() (left time.Duration)
- func (ds *DownloadStatus) TotalSize() int64
- func (ds *DownloadStatus) UpdateSpeeds()
- type DownloadStatuser
- type Range
- type RangeGenMode
- type RangeList
- type RangeListGen
- func (gen *RangeListGen) GenRange() (index int, r *Range)
- func (gen *RangeListGen) IsDone() bool
- func (gen *RangeListGen) LoadBegin() (begin int64)
- func (gen *RangeListGen) LoadBlockSize() (blockSize int64)
- func (gen *RangeListGen) RangeCount() (rangeCount int)
- func (gen *RangeListGen) RangeGenMode() RangeGenMode
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownRangeGenMode RangeGenMode 非法 ErrUnknownRangeGenMode = errors.New("Unknown RangeGenMode") )
Functions ¶
This section is empty.
Types ¶
type DownloadInstanceInfo ¶
type DownloadInstanceInfo struct { DownloadStatus *DownloadStatus Ranges RangeList }
DownloadInstanceInfo 状态详细信息, 用于导出状态文件
type DownloadInstanceInfoExport ¶
type DownloadInstanceInfoExport struct { RangeGenMode RangeGenMode `json:"rangeGenMode,omitempty"` TotalSize int64 `json:"totalSize,omitempty"` GenBegin int64 `json:"genBegin,omitempty"` BlockSize int64 `json:"blockSize,omitempty"` Ranges []*Range `json:"ranges,omitempty"` }
DownloadInstanceInfoExport 断点续传
func (*DownloadInstanceInfoExport) GetInstanceInfo ¶
func (m *DownloadInstanceInfoExport) GetInstanceInfo() (eii *DownloadInstanceInfo)
GetInstanceInfo 从断点信息获取下载状态
func (*DownloadInstanceInfoExport) SetInstanceInfo ¶
func (m *DownloadInstanceInfoExport) SetInstanceInfo(eii *DownloadInstanceInfo)
SetInstanceInfo 从下载状态导出断点信息
type DownloadStatus ¶
type DownloadStatus struct {
// contains filtered or unexported fields
}
DownloadStatus 下载状态及统计信息
func NewDownloadStatus ¶
func NewDownloadStatus() *DownloadStatus
NewDownloadStatus 初始化DownloadStatus
func (*DownloadStatus) AddDownloaded ¶
func (ds *DownloadStatus) AddDownloaded(d int64)
AddDownloaded 增加已下载数据量
func (*DownloadStatus) AddSpeedsDownloaded ¶
func (ds *DownloadStatus) AddSpeedsDownloaded(d int64)
AddSpeedsDownloaded 增加已下载数据量, 用于统计速度
func (*DownloadStatus) AddTotalSize ¶
func (ds *DownloadStatus) AddTotalSize(size int64)
AddTotalSize 增加总大小 (不支持多线程)
func (*DownloadStatus) ClearMaxSpeeds ¶
func (ds *DownloadStatus) ClearMaxSpeeds()
ClearMaxSpeeds 清空统计最大速度, 原子操作
func (*DownloadStatus) Downloaded ¶
func (ds *DownloadStatus) Downloaded() int64
Downloaded 返回已下载数据量
func (*DownloadStatus) RangeListGen ¶
func (ds *DownloadStatus) RangeListGen() *RangeListGen
RangeListGen 返回RangeListGen
func (*DownloadStatus) SetMaxSpeeds ¶
func (ds *DownloadStatus) SetMaxSpeeds(speeds int64)
SetMaxSpeeds 设置最大速度, 原子操作
func (*DownloadStatus) SetRangeListGen ¶
func (ds *DownloadStatus) SetRangeListGen(gen *RangeListGen)
SetRangeListGen 设置RangeListGen
func (*DownloadStatus) SetRateLimit ¶
func (ds *DownloadStatus) SetRateLimit(rl *speeds.RateLimit)
SetRateLimit 设置限速
func (*DownloadStatus) SetTotalSize ¶
func (ds *DownloadStatus) SetTotalSize(size int64)
SetTotalSize 设置总大小
func (*DownloadStatus) SpeedsPerSecond ¶
func (ds *DownloadStatus) SpeedsPerSecond() int64
SpeedsPerSecond 返回每秒速度
func (*DownloadStatus) TimeElapsed ¶
func (ds *DownloadStatus) TimeElapsed() (elapsed time.Duration)
TimeElapsed 返回花费的时间
func (*DownloadStatus) TimeLeft ¶
func (ds *DownloadStatus) TimeLeft() (left time.Duration)
TimeLeft 返回预计剩余时间
func (*DownloadStatus) UpdateSpeeds ¶
func (ds *DownloadStatus) UpdateSpeeds()
UpdateSpeeds 更新speeds
type DownloadStatuser ¶
type DownloadStatuser interface { TotalSize() int64 Downloaded() int64 SpeedsPerSecond() int64 TimeElapsed() time.Duration // 已开始时间 TimeLeft() time.Duration // 预计剩余时间, 负数代表未知 }
DownloadStatuser 下载状态接口
type RangeGenMode ¶
type RangeGenMode int32
RangeGenMode 线程分配方式
const ( // DefaultBlockSize 默认的BlockSize DefaultBlockSize = 256 * converter.KB // RangeGenMode_Default 根据parallel平均生成 RangeGenMode_Default RangeGenMode = 0 // RangeGenMode_BlockSize 根据blockSize生成 RangeGenMode_BlockSize RangeGenMode = 1 )
type RangeListGen ¶
type RangeListGen struct {
// contains filtered or unexported fields
}
RangeListGen Range 生成器
func NewRangeListGenBlockSize ¶
func NewRangeListGenBlockSize(totalSize, begin, blockSize int64) *RangeListGen
NewRangeListGenBlockSize 初始化Range生成器, 根据blockSize生成
func NewRangeListGenDefault ¶
func NewRangeListGenDefault(totalSize, begin int64, count, parallel int) *RangeListGen
NewRangeListGenDefault 初始化默认Range生成器, 根据parallel平均生成
func (*RangeListGen) GenRange ¶
func (gen *RangeListGen) GenRange() (index int, r *Range)
GenRange 生成 Range
func (*RangeListGen) LoadBegin ¶
func (gen *RangeListGen) LoadBegin() (begin int64)
LoadBegin 返回begin
func (*RangeListGen) LoadBlockSize ¶
func (gen *RangeListGen) LoadBlockSize() (blockSize int64)
LoadBlockSize 返回blockSize
func (*RangeListGen) RangeCount ¶
func (gen *RangeListGen) RangeCount() (rangeCount int)
RangeCount 返回预计生成的Range数量
func (*RangeListGen) RangeGenMode ¶
func (gen *RangeListGen) RangeGenMode() RangeGenMode
RangeGenMode 返回Range生成方式