Documentation ¶
Index ¶
- Constants
- Variables
- func FileExist(path string) bool
- func FilterFileNameFormWindows(name string) string
- func FormatFileSize(fileSize int64) string
- func GetFileName(uri, contentDisposition, contentType string, headinfo []byte) string
- func GetStringLength(str string) int
- func SetHttpMaxIdleConnsPerHost(d int)
- func SetHttpProxy(d func(*http.Request) (*url.URL, error))
- func SetHttpResponseHeaderTimeout(d time.Duration)
- func SetHttpTLSHandshakeTimeout(d time.Duration)
- func SetHttpTimeout(d time.Duration)
- type ControlFile
- func (cf *ControlFile) AddCompleted(key int, completed int64)
- func (cf *ControlFile) AddDownloadPiece(completed, start, end int64) int
- func (cf *ControlFile) Close()
- func (cf *ControlFile) Encoding() *bytes.Buffer
- func (cf *ControlFile) GetBreakpointResume() bool
- func (cf *ControlFile) GetCompletedLength() int64
- func (cf *ControlFile) GetDownloadPiece() []*DownloadPiece
- func (cf *ControlFile) ParseControlfile(data []byte) *ControlFile
- func (cf *ControlFile) Remove() error
- func (cf *ControlFile) Save()
- func (cf *ControlFile) SetSaveEvent(d func())
- type DownloadPiece
- type FileController
- func (fileController *FileController) Close() error
- func (fileController *FileController) Copy(ctx context.Context, src io.Reader, id int, start int64, dataSize int64) error
- func (fileController *FileController) Rateread(ctx context.Context, src io.Reader, buf []byte) (n int, err error)
- func (fileController *FileController) SetWriteChangeEvent(d func(id int, n int))
- func (fileController *FileController) Sync() error
- func (fileController *FileController) Truncate(size int64) error
- type FileWriteAt
- type IoProxyReader
- type WaitGroupPool
Constants ¶
View Source
const ( // CONTROLFILESIZE 控制文件最小长度 CONTROLFILESIZE = 34 // DOWNLOADBLOCKSIZE 一个下载块的长度 DOWNLOADBLOCKSIZE = 24 // CONTROLFILEHEAD 控制文件头 CONTROLFILEHEAD = "rain" )
Variables ¶
View Source
var HttpClient = &http.Client{ Transport: &http.Transport{ Proxy: http.ProxyFromEnvironment, DisableCompression: true, ResponseHeaderTimeout: 5 * time.Second, TLSHandshakeTimeout: 10 * time.Second, TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, MaxIdleConnsPerHost: 10, }, Timeout: time.Minute * 5, }
HttpClient 全局使用的 HTTP 客户端
Functions ¶
func GetFileName ¶
GetFileName 自动获取资源文件名称 名称获取的顺序:响应头 content-disposition 的 filename 字段、uri.Path 中的 \ 最后的字符、随机生成 文件后缀的获取顺序:文件魔数、响应头 content-type 匹配系统中的库
func SetHttpMaxIdleConnsPerHost ¶
func SetHttpMaxIdleConnsPerHost(d int)
func SetHttpTimeout ¶
Types ¶
type ControlFile ¶
type ControlFile struct {
// contains filtered or unexported fields
}
ControlFile 控制文件,记录了断点下载所需要的信息
func NewControlfile ¶
NewControlfile 创建控制文件
func (*ControlFile) AddCompleted ¶
func (cf *ControlFile) AddCompleted(key int, completed int64)
AddCompleted 添加数据块已完成的数据量
func (*ControlFile) AddDownloadPiece ¶
func (cf *ControlFile) AddDownloadPiece(completed, start, end int64) int
AddDownloadPiece 添加下载块
func (*ControlFile) GetBreakpointResume ¶
func (cf *ControlFile) GetBreakpointResume() bool
GetBreakpointResume 获取是否需要单点续传
func (*ControlFile) GetCompletedLength ¶
func (cf *ControlFile) GetCompletedLength() int64
GetCompletedLength 获取已下载长度
func (*ControlFile) GetDownloadPiece ¶
func (cf *ControlFile) GetDownloadPiece() []*DownloadPiece
GetDownloadPiece 获取下载块
func (*ControlFile) ParseControlfile ¶
func (cf *ControlFile) ParseControlfile(data []byte) *ControlFile
ParseControlfile 解析控制文件
func (*ControlFile) SetSaveEvent ¶
func (cf *ControlFile) SetSaveEvent(d func())
SetSaveEvent 设置控制文件保存事件
type DownloadPiece ¶
type DownloadPiece struct { // completed 8 字节 已下载大小 Completed int64 // start 8 字节 开始字节 Start int64 // end 8 字节 结束字节 End int64 }
DownloadPiece 下载块信息
type FileController ¶
type FileController struct {
// contains filtered or unexported fields
}
FileController 文件控制器
func NewFileController ¶
func NewFileController(filepath string, cl *int64, diskCache, speedLimit int, perm fs.FileMode) (*FileController, error)
NewFileController 创建文件控制器
func (*FileController) Close ¶
func (fileController *FileController) Close() error
func (*FileController) Copy ¶
func (fileController *FileController) Copy(ctx context.Context, src io.Reader, id int, start int64, dataSize int64) error
Copy 数据拷贝
func (*FileController) Rateread ¶
func (fileController *FileController) Rateread(ctx context.Context, src io.Reader, buf []byte) (n int, err error)
Rateread 限速读取
func (*FileController) SetWriteChangeEvent ¶
func (fileController *FileController) SetWriteChangeEvent(d func(id int, n int))
func (*FileController) Sync ¶
func (fileController *FileController) Sync() error
func (*FileController) Truncate ¶
func (fileController *FileController) Truncate(size int64) error
type FileWriteAt ¶
type FileWriteAt struct {
// contains filtered or unexported fields
}
FileWriteAt 指定位置写入
func NewFileWriteAt ¶
NewFileWriteAt 创建指定文件位置写入器
type IoProxyReader ¶
IoProxyReader 代理 io 读
func (*IoProxyReader) Close ¶
func (r *IoProxyReader) Close() (err error)
Close the wrapped reader when it implements io.Closer
type WaitGroupPool ¶
type WaitGroupPool struct {
// contains filtered or unexported fields
}
WaitGroupPool sync.WaitGroup 池
func NewWaitGroupPool ¶
func NewWaitGroupPool(size int) *WaitGroupPool
NewWaitGroupPool 创建一个 size 大小的 sync.WaitGroup 池
Source Files ¶
Click to show internal directories.
Click to hide internal directories.