Documentation ¶
Index ¶
- func BarThreadOne(dl *Downloader, startSize, size int64, r io.Reader) io.Reader
- func Defer(dl *Downloader)
- func GetFileCreateTime(sys interface{}) int64
- func GetFilename(url, contentDisposition, contentType string) string
- func GetFiltrationFilename(name string) string
- type BarThreadOneReader
- type DownloadInfo
- type Downloader
- func (dl *Downloader) AddDfer(d OnDefer) *Downloader
- func (dl *Downloader) AddHeader(name, value string) *Downloader
- func (dl *Downloader) DownloadOver() error
- func (dl *Downloader) GetBarTemplate() pb.ProgressBarTemplate
- func (dl *Downloader) GetIsBar() bool
- func (dl *Downloader) GetPath() string
- func (dl *Downloader) GetTempName() string
- func (dl *Downloader) GetTempPath() string
- func (dl *Downloader) GetThreadNum() int
- func (dl *Downloader) IsExist(size int64, lastModified string) error
- func (dl *Downloader) IsRanges() bool
- func (dl *Downloader) ProxyReader(r io.Reader) io.Reader
- func (dl *Downloader) Response(onRequest OnRequest) (*http.Response, error)
- func (dl *Downloader) SetBarTemplate(BarTemplate pb.ProgressBarTemplate) *Downloader
- func (dl *Downloader) SetBody(body io.Reader) *Downloader
- func (dl *Downloader) SetClient(Client *http.Client) *Downloader
- func (dl *Downloader) SetHeader(name, value string) *Downloader
- func (dl *Downloader) SetIsBar(i bool) *Downloader
- func (dl *Downloader) SetMethod(method string) *Downloader
- func (dl *Downloader) SetOnProgress(f OnProgress) *Downloader
- func (dl *Downloader) SetOutputName(outputName string) *Downloader
- func (dl *Downloader) SetOutputPath(outputPath string) *Downloader
- func (dl *Downloader) SetThreadNum(n int) *Downloader
- func (dl *Downloader) Start() error
- func (dl *Downloader) StatSpeed()
- func (dl *Downloader) Thread() error
- func (dl *Downloader) ThreadOne() error
- type IoProxyReader
- type OnDefer
- type OnProgress
- type OnRequest
- type Options
- type ProgressBar
- type Rquest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BarThreadOne ¶
BarThreadOne 单线程下载进度条
func GetFilename ¶
GetFilename 生成文件名称
func GetFiltrationFilename ¶
GetFiltrationFilename 返回过滤后的文件名
Types ¶
type BarThreadOneReader ¶
BarThreadOneReader 单线程下载进度条,读取IO
type DownloadInfo ¶
type DownloadInfo struct { Size int64 // 文件总大小 Speed int64 // 每秒下载大小,用来计算下载速度/s DownloadedSize *int64 // 已下载文件大小,原子操作 }
DownloadInfo 下载时的信息
func (*DownloadInfo) AddDownloadedSize ¶
func (info *DownloadInfo) AddDownloadedSize(v int64)
AddDownloadedSize 增加已下载文件大小
func (*DownloadInfo) GetDownloadedSize ¶
func (info *DownloadInfo) GetDownloadedSize() int64
GetDownloadedSize 获取已下载文件大小
type Downloader ¶
type Downloader struct { URL string // 下载URL Options *Options // 下载参数 ProgressBar ProgressBar // 进度条参数 Defer []OnDefer // 下载关闭事件 Info *DownloadInfo // 下载时的信息 OnProgress OnProgress // 下载进度回调 }
Downloader 下载信息
func (*Downloader) AddDfer ¶
func (dl *Downloader) AddDfer(d OnDefer) *Downloader
AddDfer 添加Defer 下载关闭事件
func (*Downloader) AddHeader ¶
func (dl *Downloader) AddHeader(name, value string) *Downloader
AddHeader 添加请求时的Header
func (*Downloader) DownloadOver ¶
func (dl *Downloader) DownloadOver() error
DownloadOver 下载完成,强制覆盖,修改文件名称
func (*Downloader) GetBarTemplate ¶
func (dl *Downloader) GetBarTemplate() pb.ProgressBarTemplate
GetBarTemplate 获取进度条模板
func (*Downloader) IsExist ¶
func (dl *Downloader) IsExist(size int64, lastModified string) error
IsExist 目录与文件是否存在处理 自动创建目录 检查文件是否完整,若出现异常直接返回不完整
func (*Downloader) ProxyReader ¶
func (dl *Downloader) ProxyReader(r io.Reader) io.Reader
ProxyReader 代理io读
func (*Downloader) Response ¶
func (dl *Downloader) Response(onRequest OnRequest) (*http.Response, error)
Response 创建Response
func (*Downloader) SetBarTemplate ¶
func (dl *Downloader) SetBarTemplate(BarTemplate pb.ProgressBarTemplate) *Downloader
SetBarTemplate 设置进度条模板
func (*Downloader) SetBody ¶
func (dl *Downloader) SetBody(body io.Reader) *Downloader
SetBody 设置请求Body
func (*Downloader) SetClient ¶
func (dl *Downloader) SetClient(Client *http.Client) *Downloader
SetClient 设置请求Client
func (*Downloader) SetHeader ¶
func (dl *Downloader) SetHeader(name, value string) *Downloader
SetHeader 设置请求时的Header
func (*Downloader) SetMethod ¶
func (dl *Downloader) SetMethod(method string) *Downloader
SetMethod 设置请求Method
func (*Downloader) SetOnProgress ¶
func (dl *Downloader) SetOnProgress(f OnProgress) *Downloader
SetOnProgress 设置进度事件
func (*Downloader) SetOutputName ¶
func (dl *Downloader) SetOutputName(outputName string) *Downloader
SetOutputName 设置输出文件名称
func (*Downloader) SetOutputPath ¶
func (dl *Downloader) SetOutputPath(outputPath string) *Downloader
SetOutputPath 设置输出目录
func (*Downloader) SetThreadNum ¶
func (dl *Downloader) SetThreadNum(n int) *Downloader
SetThreadNum 设置下载线程数
type IoProxyReader ¶
IoProxyReader 代理io读
func (*IoProxyReader) Close ¶
func (r *IoProxyReader) Close() (err error)
Close the wrapped reader when it implements io.Closer
type OnProgress ¶
type OnProgress func(size, speed, downloadedSize int64)
OnProgress 载进度回调 size 文件总大小,读取不出文件大小为0 speed 每秒下载大小,用来计算下载速度/s downloadedSize 已下载文件大小
type Options ¶
type Options struct { OutputPath string // 保存路径 OutputName string // 保存文件名 为空:自动生成 Replace bool // 是否允许覆盖文件 Rquest Rquest // 请求参数 ThreadNum int // 下载线程数 }
Options 下载参数
type ProgressBar ¶
type ProgressBar struct { IsBar bool // 是否显示进度条 BarTemplate pb.ProgressBarTemplate // 进度条样式 }
ProgressBar 进度条参数