downloader

package
v3.2.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2018 License: Apache-2.0 Imports: 15 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 DownloadStatus

type DownloadStatus struct {
	Downloaded int64 `json:"downloaded"`
	Speeds     int64
	MaxSpeeds  int64
	// contains filtered or unexported fields
}

DownloadStatus 状态

type Downloader

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

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

Downloader 下载详情

func NewDownloader

func NewDownloader(url, savePath string, h *requester.HTTPClient) (der *Downloader, err error)

NewDownloader 创建新的文件下载

func (*Downloader) GetStatusChan

func (der *Downloader) GetStatusChan() <-chan DownloadStatus

GetStatusChan 返回 DownloadStatus 对象的 channel

func (*Downloader) OnError

func (der *Downloader) OnError(fn func(int, error))

OnError 任务出错时触发的事件

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

func (*Downloader) OnFinish

func (der *Downloader) OnFinish(fn func())

OnFinish 任务完成时触发的事件

func (*Downloader) OnStart

func (der *Downloader) OnStart(fn func())

OnStart 任务开始时触发的事件

func (*Downloader) StartDownload

func (der *Downloader) StartDownload()

StartDownload 开始下载

type ErrData

type ErrData struct {
	ErrorCode int    `json:"error_code"`
	ErrorMsg  string `json:"error_msg"`
}

Jump to

Keyboard shortcuts

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