downloader

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2015 License: Apache-2.0 Imports: 6 Imported by: 0

README

downloader

Go Walker GoDoc

HTTP file downloader

功能

  • 统计信息
  • 多线程下载
  • 断点续传
  • 线程数量动态修改
  • 线程自动分配(均衡线程负载)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 最大线程数量
	MaxThread = 5
	// 缓冲区大小
	CacheSize = 1024
)

Functions

This section is empty.

Types

type Block

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

type FileDl

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

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

func NewFileDl

func NewFileDl(url string, file *os.File, size int64) (*FileDl, error)

创建新的文件下载

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

func (FileDl) GetStatus

func (f FileDl) GetStatus() Status

获取下载统计信息

func (*FileDl) OnError

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

任务出错时触发的事件

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

func (*FileDl) OnFinish

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

任务完成时触发的事件

func (*FileDl) OnPause

func (f *FileDl) OnPause(fn func())

任务暂停时触发的事件

func (*FileDl) OnResume

func (f *FileDl) OnResume(fn func())

任务继续时触发的事件

func (*FileDl) OnStart

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

任务开始时触发的事件

func (*FileDl) Pause

func (f *FileDl) Pause()

暂停下载

func (*FileDl) Resume

func (f *FileDl) Resume()

继续下载

func (*FileDl) Start

func (f *FileDl) Start()

开始下载

type Status

type Status struct {
	Downloaded int64
	Speeds     int64
}

Jump to

Keyboard shortcuts

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