protocol

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// STATUS_READY 准备完成
	STATUS_READY = Status(iota)
	// STATUS_RUNNING 运行中
	STATUS_RUNNING
	// STATUS_FINISH 完成
	STATUS_FINISH
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTP

type HTTP struct {
	// Debug 调试错误时开启
	Debug bool
	// threadCount 多线程下载时最多同时下载一个文件的最大线程,默认为 1
	ThreadCount int
	// threadSize 多线程下载时每个线程下载的大小,每个线程都会有一个自己下载大小的缓冲区,默认为 20M
	ThreadSize int
	// diskCache 磁盘缓冲区大小,默认为 16M
	DiskCache int
	// speedLimit 下载速度限制,默认为 0 无限制
	SpeedLimit int
	// createDir 当需要创建目录时,是否创建目录,默认为 true
	CreateDir bool
	// allowOverwrite 是否允许覆盖文件,默认为 true
	AllowOverwrite bool
	// autoFileRenaming 文件自动重命名,新文件名在名称之后扩展名之前加上一个点和一个数字(1..9999)。默认:true
	AutoFileRenaming bool
	// breakpointResume 是否启用断点续传,默认为 true
	BreakpointResume bool
	// autoSaveTnterval 自动保存控制文件的时间,默认为 1 秒
	AutoSaveTnterval time.Duration
	// timeout 下载总超时时间,默认为 10 分钟
	Timeout time.Duration
	// retryNumber 最多重试次数,默认为 5
	RetryNumber int
	// retryTime 重试时的间隔时间,默认为 0
	RetryTime time.Duration
	// tempfileExt 临时文件后缀, 默认为 temp.rain
	TempfileExt string

	// client http 客户端
	Client *http.Client
	// 下载链接、输出目录、输出名称
	URI, Outdir, Outname, Outpath string
	// Method 默认为 GET
	Method string
	// Body 请求时的 Body,默认为 nil
	Body io.Reader
	// Header 请求时的头部信息
	Header http.Header
	// Perm 新建文件的权限, 默认为 0600
	Perm fs.FileMode
	// contains filtered or unexported fields
}

func (*HTTP) Close

func (h *HTTP) Close()

Close 释放资源

func (*HTTP) Done

func (h *HTTP) Done() <-chan error

Done 返回下载完成 chan 指针

func (*HTTP) Start

func (h *HTTP) Start(ctx context.Context) error

Start 开始执行下载

func (*HTTP) Stat

func (h *HTTP) Stat() *HttpStat

Stat 返回下载器的进度信息

func (*HTTP) Wait

func (h *HTTP) Wait() error

Wait 等待下载完成

type HttpStat

type HttpStat struct {
	// Status 状态
	Status Status

	// TotalLength 文件总大小
	TotalLength int64

	// CompletedLength 已下载的文件大小
	CompletedLength int64

	// DownloadSpeed 每秒下载字节数
	DownloadSpeed int64

	// EstimatedTime 预计下载完成还需要的时间
	EstimatedTime time.Duration

	// Progress 下载进度, 长度为 100
	Progress int

	// Connections 与资源服务器的连接数
	Connections int

	// Outpath 文件输出路径
	Outpath string
}

HttpStat 下载进行中的信息

type Status

type Status int

Jump to

Keyboard shortcuts

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