downloader

package
v3.2.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DownloadingFileSuffix 断点续传临时文件后缀
	DownloadingFileSuffix = ".baidupcs_go_downloading"
)
View Source
var (

	// FileNameRE 正则表达式: 匹配文件名
	FileNameRE = regexp.MustCompile("filename=\"(.*?)\"")
)

Functions

func DoDownload

func DoDownload(url string, fileName string)

DoDownload 简单网络下载器, 使用默认下载线程, 通过调用 SetMaxThread 来修改默认下载线程

func SetCacheSize

func SetCacheSize(size int)

SetCacheSize 设置缓冲大小

func SetMaxParallel

func SetMaxParallel(t int)

SetMaxParallel 设置最大线程

Types

type Block

type Block struct {
	Begin int64 `json:"begin"`
	End   int64 `json:"end"`

	Final bool `json:"isfinal"` // 最后线程, 因为最后的下载线程, 需要另外做处理
	// contains filtered or unexported fields
}

Block 下载区块

type FileDl

type FileDl struct {
	URL  string   // 下载地址
	Size int64    // 文件大小
	File *os.File // 要写入的文件

	BlockList blockList // 用于记录未下载的文件块起始位置
	// contains filtered or unexported fields
}

FileDl 下载详情

func NewFileDl

func NewFileDl(h *requester.HTTPClient, url, savePath string) (*FileDl, error)

NewFileDl 创建新的文件下载

如果 size <= 0 则自动获取文件大小

func (FileDl) GetStatus

func (f FileDl) GetStatus() status

GetStatus 获取下载统计信息

func (*FileDl) OnError

func (f *FileDl) OnError(fn func(int, error))

OnError 任务出错时触发的事件

errCode为错误码,errStr为错误描述

func (*FileDl) OnFinish

func (f *FileDl) OnFinish(fn func())

OnFinish 任务完成时触发的事件

func (*FileDl) OnStart

func (f *FileDl) OnStart(fn func())

OnStart 任务开始时触发的事件

func (*FileDl) Start

func (f *FileDl) Start()

Start 开始下载

Jump to

Keyboard shortcuts

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