transfer

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) MaxSpeeds

func (ds *DownloadStatus) MaxSpeeds() int64

MaxSpeeds 返回最大速度

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) TotalSize

func (ds *DownloadStatus) TotalSize() int64

TotalSize 返回总大小

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 Range

type Range struct {
	Begin int64 `json:"begin,omitempty"`
	End   int64 `json:"end,omitempty"`
}

func (*Range) AddBegin

func (r *Range) AddBegin(i int64) (newi int64)

AddBegin 增加Begin, 原子操作

func (*Range) Len

func (r *Range) Len() int64

Len 长度

func (*Range) LoadBegin

func (r *Range) LoadBegin() int64

LoadBegin 读取Begin, 原子操作

func (*Range) LoadEnd

func (r *Range) LoadEnd() int64

LoadEnd 读取End, 原子操作

func (*Range) ShowDetails

func (r *Range) ShowDetails() string

ShowDetails 显示Range细节

func (*Range) StoreBegin

func (r *Range) StoreBegin(end int64)

StoreBegin 储存End, 原子操作

func (*Range) StoreEnd

func (r *Range) StoreEnd(end int64)

StoreEnd 储存End, 原子操作

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 RangeList

type RangeList []*Range

RangeList 请求范围列表

func (*RangeList) Len

func (rl *RangeList) Len() int64

Len 获取所有的Range的剩余长度

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) IsDone

func (gen *RangeListGen) IsDone() bool

IsDone 是否已分配完成

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生成方式

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL