download

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GoNum  = 10
	MaxErr = 10
)

Variables

View Source
var (
	ErrNilUpload         = errors.New("upload can't be nil")
	ErrLargeUpload       = errors.New("upload body is to large")
	ErrUploadNotFound    = errors.New("upload not found")
	ErrResumeNotEnabled  = errors.New("resuming not enabled")
	ErrFingerprintNotSet = errors.New("fingerprint not set")
	ErrNilDownload       = errors.New("download can't be nil")
	ErrDownloadNotFound  = errors.New("download not found")
)

Functions

This section is empty.

Types

type ClientError

type ClientError struct {
	Code int
	Body []byte
}

func (ClientError) Error

func (c ClientError) Error() string

type Download

type Download struct {
	Fingerprint string // download任务的标识
	Metadata    downloadMeta
	// contains filtered or unexported fields
}

func NewDownload

func NewDownload(fileUrl, fileName, basePath, tempPath string) (*Download, error)

先判断当前环境是否已经有这个下载任务了

func (*Download) ChunckStream

func (u *Download) ChunckStream(chunck int64) (io.WriteSeeker, error)

func (*Download) DelTempDir

func (u *Download) DelTempDir() error

func (*Download) EncodedMetadata

func (u *Download) EncodedMetadata() string

func (*Download) ErrClean

func (u *Download) ErrClean() error

清除所有错误文件,包括stream以及temp文件 stream不用,因为合并的时候会移动到0从新开始写入

func (*Download) Finished

func (u *Download) Finished() bool

func (*Download) MergeStream

func (u *Download) MergeStream(maxChunck int64) error

func (*Download) Offset

func (u *Download) Offset() int64

func (*Download) Progress

func (u *Download) Progress() int64

func (*Download) Size

func (u *Download) Size() int64

type DownloadClient

type DownloadClient struct {
	Config *DownloadConfig
	// contains filtered or unexported fields
}

func NewDownloadClient

func NewDownloadClient(url string, config *DownloadConfig) (*DownloadClient, error)

func (*DownloadClient) Close added in v0.0.8

func (c *DownloadClient) Close() error

func (*DownloadClient) CreateDownload

func (c *DownloadClient) CreateDownload(download *Download) (*Downloader, error)

开始新的下载

func (*DownloadClient) CreateOrResumeDownload

func (c *DownloadClient) CreateOrResumeDownload(d *Download) (*Downloader, error)

开始新的或者恢复下载

func (*DownloadClient) DelFile

func (c *DownloadClient) DelFile(baseurl, filename string) error

发送调用,删除某个文件

func (*DownloadClient) FileList

func (c *DownloadClient) FileList() ([]string, error)

func (*DownloadClient) GetMd5

func (c *DownloadClient) GetMd5(baseUrl, filename string) (string, error)

func (*DownloadClient) ResumeDownload

func (c *DownloadClient) ResumeDownload(d *Download) (*Downloader, error)

恢复下载

type DownloadConfig

type DownloadConfig struct {
	Store   store.DownloadStore
	Resume  bool
	TempDir string
}

type Downloader

type Downloader struct {
	// contains filtered or unexported fields
}

func (*Downloader) Abort

func (d *Downloader) Abort()

func (*Downloader) CheckMd5

func (d *Downloader) CheckMd5(fingerprint string) error

func (*Downloader) Download

func (d *Downloader) Download(isDel bool) error

下载文件,isDel下载完成后是否删除远端的文件

func (*Downloader) IsAborted

func (d *Downloader) IsAborted() bool

func (*Downloader) MergeAndCheck

func (d *Downloader) MergeAndCheck(maxTruncate int64, isDel bool) error

注意: 如果isDel是true,那么说明远端文件会删除,也就是这里只能校验一次 合并strem,校验md5,如果校验失败进行删除, isDel 如果校验成功是否删除远程文件

func (*Downloader) Offset

func (d *Downloader) Offset() int64

Jump to

Keyboard shortcuts

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