internal

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GoNum  = 10
	MaxErr = 10
)
View Source
const (
	ProtocolVersion = "1.0.0"
)

Variables

View Source
var (
	ErrChuckSize         = errors.New("chunk size must be greater than zero")
	ErrNilLogger         = errors.New("logger can't be nil")
	ErrNilStore          = errors.New("store can't be nil if Resume is enable")
	ErrNilUpload         = errors.New("upload can't be nil")
	ErrLargeUpload       = errors.New("upload body is to large")
	ErrVersionMismatch   = errors.New("protocol version mismatch")
	ErrOffsetMismatch    = errors.New("upload offset mismatch")
	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

func FileMd5ByContent added in v0.0.3

func FileMd5ByContent(file string) (string, error)

获取文件的md5字符串 根据文件内容进行md5

func FileMd5BySpec added in v0.0.3

func FileMd5BySpec(file string) (string, error)

获取文件的md5字符串 根据文件名字、文件大小 文件数据的前100byte+后100byte作为md5数据

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 added in v0.0.3

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) CreateDownload

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

开始新的下载

func (*DownloadClient) CreateOrResumeDownload

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

开始新的或者恢复下载

func (*DownloadClient) DelFile added in v0.0.3

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

发送调用,删除某个文件

func (*DownloadClient) FileList added in v0.0.2

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

func (*DownloadClient) GetMd5 added in v0.0.3

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 added in v0.0.3

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 added in v0.0.3

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

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

func (*Downloader) Offset

func (d *Downloader) Offset() int64

type Metadata

type Metadata map[string]string

type Upload

type Upload struct {
	Fingerprint string
	Metadata    Metadata
	// contains filtered or unexported fields
}

func NewUpload

func NewUpload(reader io.Reader, size int64, metadata Metadata, fingerprint string) (*Upload, error)

NewUpload creates a new upload from an io.Reader.

func NewUploadFromBytes

func NewUploadFromBytes(b []byte) (*Upload, error)

NewUploadFromBytes creates a new upload from a byte array.

func NewUploadFromFile

func NewUploadFromFile(f *os.File) (*Upload, error)

NewUploadFromFile creates a new Upload from an os.File.

func (*Upload) EncodedMetadata

func (u *Upload) EncodedMetadata() string

EncodedMetadata encodes the upload metadata.

func (*Upload) Finished

func (u *Upload) Finished() bool

Returns whether this upload is finished or not.

func (*Upload) Offset

func (u *Upload) Offset() int64

Returns the current upload offset.

func (*Upload) Progress

func (u *Upload) Progress() int64

Returns the progress in a percentage.

func (*Upload) Size

func (u *Upload) Size() int64

Returns the size of the upload body.

type UploadClient

type UploadClient struct {
	Config  *UploadConfig
	Url     string
	Version string
	Header  http.Header
	// contains filtered or unexported fields
}

Client represents the tus client. You can use it in goroutines to create parallels uploads.

func NewUploadClient

func NewUploadClient(url string, config *UploadConfig) (*UploadClient, error)

NewClient creates a new tus client.

func (*UploadClient) CreateOrResumeUpload

func (c *UploadClient) CreateOrResumeUpload(u *Upload) (*Uploader, error)

CreateOrResumeUpload resumes the upload if already created or creates a new upload in the server.

func (*UploadClient) CreateUpload

func (c *UploadClient) CreateUpload(u *Upload) (*Uploader, error)

CreateUpload creates a new upload in the server.

func (*UploadClient) Do

func (c *UploadClient) Do(req *http.Request) (*http.Response, error)

func (*UploadClient) ResumeUpload

func (c *UploadClient) ResumeUpload(u *Upload) (*Uploader, error)

ResumeUpload resumes the upload if already created, otherwise it will return an error.

type UploadConfig

type UploadConfig struct {
	// ChunkSize divide the file into chunks.
	ChunkSize int64
	// Resume enables resumable upload.
	Resume bool
	// OverridePatchMethod allow to by pass proxies sendind a POST request instead of PATCH.
	OverridePatchMethod bool
	// Store map an upload's fingerprint with the corresponding upload URL.
	// If Resume is true the Store is required.
	Store store.UploadStore
	// Set custom header values used in all requests.
	Header http.Header
	// HTTP Client
	HttpClient *http.Client
}

Config provides a way to configure the Client depending on your needs.

func DefaultUploadConfig

func DefaultUploadConfig() *UploadConfig

DefaultConfig return the default Client configuration.

func (*UploadConfig) Validate

func (c *UploadConfig) Validate() error

Validate validates the custom configuration.

type Uploader

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

func NewUploader

func NewUploader(client *UploadClient, url string, upload *Upload, offset int64) *Uploader

NewUploader creates a new Uploader.

func (*Uploader) Abort

func (u *Uploader) Abort()

Abort aborts the upload process. It doens't abort the current chunck, only the remaining.

func (*Uploader) IsAborted

func (u *Uploader) IsAborted() bool

IsAborted returns true if the upload was aborted.

func (*Uploader) NotifyUploadProgress

func (u *Uploader) NotifyUploadProgress(c chan Upload)

Subscribes to progress updates.

func (*Uploader) Offset

func (u *Uploader) Offset() int64

Offset returns the current offset uploaded.

func (*Uploader) Upload

func (u *Uploader) Upload() error

Upload uploads the entire body to the server.

func (*Uploader) UploadChunck

func (u *Uploader) UploadChunck() error

UploadChunck uploads a single chunck.

func (*Uploader) Url

func (u *Uploader) Url() string

Url returns the upload url.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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