Documentation
¶
Overview ¶
Package downloader 多线程下载器
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DownloadingFileSuffix 断点续传临时文件后缀 DownloadingFileSuffix = ".downloader_downloading" // MinParallelSize 单个线程最小的数据量 MinParallelSize = 128 * pcsutil.KB )
Functions ¶
Types ¶
type Block ¶
type Block struct {
Begin int64 `json:"begin"`
End int64 `json:"end"`
IsFinal bool `json:"isfinal"` // 最后线程, 因为最后的下载线程, 需要另外做处理
// contains filtered or unexported fields
}
Block 下载区块
type Config ¶
type Config struct {
Client *requester.HTTPClient // http 客户端
SavePath string // relative or absulute path
Parallel int // 最大下载并发量
CacheSize int // 下载缓冲
Testing bool // 是否测试下载
}
Config 下载配置
type Downloader ¶
type Downloader struct {
OnExecute func()
OnFinish func()
OnPause func()
OnResume func()
OnCancel func() // 手动取消
OnCancelError func(code int, err error) // 中途遇到下载错误而取消的
URL string
Config Config
// contains filtered or unexported fields
}
Downloader 下载
func NewDownloader ¶
func NewDownloader(durl string, cfg Config) (der *Downloader, err error)
NewDownloader 创建新的文件下载
func (*Downloader) GetStatusChan ¶
func (der *Downloader) GetStatusChan() <-chan StatusStat
GetStatusChan 返回 Status 对象的 channel
type SpeedsStat ¶
type SpeedsStat struct {
// contains filtered or unexported fields
}
SpeedsStat 统计下载速度
func (*SpeedsStat) GetSpeedsPerSecond ¶
func (sps *SpeedsStat) GetSpeedsPerSecond() (speeds int64)
GetSpeedsPerSecond 结束统计速度, 并返回每秒的速度
type Status ¶
type Status struct {
StatusStat
BlockList BlockList `json:"block_list"` // 下载区块列表
// contains filtered or unexported fields
}
Status 下载状态
Source Files
¶
Click to show internal directories.
Click to hide internal directories.