downloader

package
v0.0.0-...-acbe8ca Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SizeHeaderOffset       = int64(0)
	BlockCountHeaderOffset = int64(8)
	DataHeaderSize         = int64(12)
)
View Source
const (
	Waiting = "Waiting"
	Running = "Running"
	Paused  = "Paused"
	Failed  = "Failed"
	Success = "Success"
)
View Source
const TaskStatusCalculatedInterval = 1 * time.Second

Variables

View Source
var BadResponse = errors.New("bad response")
View Source
var InvalidDownloadOptions = errors.New("invalid download options")
View Source
var InvalidProgressData = errors.New("invalid progress data")
View Source
var WriteAlreadyFinished = errors.New("write already finished")

Functions

func MergeBlocks

func MergeBlocks(blocks []*TaskBlock) (err error)

func RecoverApplyFunc

func RecoverApplyFunc(f func())

func RecoverGoroutine

func RecoverGoroutine(f func())

func ResolveContentRange

func ResolveContentRange(contentRange string) (int64, error)

func ResolveFileSize

func ResolveFileSize(httpClient *http.Client, link *Link) (int64, error)

Types

type BlockIterator

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

func (*BlockIterator) Next

func (it *BlockIterator) Next() (*TaskBlock, error)

type DownloadHandler

type DownloadHandler func(ctx context.Context, block *TaskBlock) error

type DownloadProcessor

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

func (*DownloadProcessor) Run

func (p *DownloadProcessor) Run()

type DownloadTask

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

func NewTask

func NewTask(optionsProvider DownloadTaskOptionsProvider) (task *DownloadTask, err error)

func (*DownloadTask) Close

func (t *DownloadTask) Close()

Close closes the download task

func (*DownloadTask) Done

func (t *DownloadTask) Done() <-chan struct{}

func (*DownloadTask) GetCompletedSize

func (t *DownloadTask) GetCompletedSize() (int64, error)

GetCompletedSize Get the completed size of the downloaded task

func (*DownloadTask) GetError

func (t *DownloadTask) GetError() error

GetError Get the current download exceptions

func (*DownloadTask) GetSize

func (t *DownloadTask) GetSize() int64

GetSize Get the total size of the files to be downloaded

func (*DownloadTask) GetStatus

func (t *DownloadTask) GetStatus() string

GetStatus get the status of the task

func (*DownloadTask) GetStatusInfo

func (t *DownloadTask) GetStatusInfo() *DownloadTaskStatus

GetStatusInfo Get the status information of the current download task

func (*DownloadTask) GetThreadCount

func (t *DownloadTask) GetThreadCount() int32

GetThreadCount Get the number of currently active download threads

func (*DownloadTask) GetTotalDownload

func (t *DownloadTask) GetTotalDownload() int64

GetTotalDownload Get the size of the downloaded data

func (*DownloadTask) Run

func (t *DownloadTask) Run()

Run Execute the current download task

type DownloadTaskOptionsBuilder

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

func NewDownloadTaskOptionsBuilder

func NewDownloadTaskOptionsBuilder() *DownloadTaskOptionsBuilder

func (*DownloadTaskOptionsBuilder) Build

func (*DownloadTaskOptionsBuilder) SetClient

func (o *DownloadTaskOptionsBuilder) SetClient(c *http.Client)

func (*DownloadTaskOptionsBuilder) SetDataStore

func (o *DownloadTaskOptionsBuilder) SetDataStore(dataStore RandomReadWriter)

func (*DownloadTaskOptionsBuilder) SetDataStoreByPath

func (o *DownloadTaskOptionsBuilder) SetDataStoreByPath(file string) (err error)

func (*DownloadTaskOptionsBuilder) SetHttpClient

func (o *DownloadTaskOptionsBuilder) SetHttpClient(httpClient *http.Client)

func (*DownloadTaskOptionsBuilder) SetMaxBlockSize

func (o *DownloadTaskOptionsBuilder) SetMaxBlockSize(maxBlockSize int)

func (*DownloadTaskOptionsBuilder) SetMinBlockSize

func (o *DownloadTaskOptionsBuilder) SetMinBlockSize(minBlockSize int)

func (*DownloadTaskOptionsBuilder) SetProgressStore

func (o *DownloadTaskOptionsBuilder) SetProgressStore(progressStore RandomReadWriter)

func (*DownloadTaskOptionsBuilder) SetProgressStoreByPath

func (o *DownloadTaskOptionsBuilder) SetProgressStoreByPath(file string) (err error)

func (*DownloadTaskOptionsBuilder) SetSize

func (o *DownloadTaskOptionsBuilder) SetSize(size int64)

func (*DownloadTaskOptionsBuilder) SetStatusUpdateInterval

func (o *DownloadTaskOptionsBuilder) SetStatusUpdateInterval(duration time.Duration)

type DownloadTaskOptionsProvider

type DownloadTaskOptionsProvider func() *downloadTaskOptions

type DownloadTaskStatus

type DownloadTaskStatus struct {
	Size          int64
	CompletedSize int64
	Status        string // Status of the download(Waiting、Running、Paused、Failed、Success)
	Speed         int64  // Download speed (bytes per second)
	Threads       int32
	Err           error
}

type HandlerWatcher

type HandlerWatcher func(in bool)
type Link struct {
	// contains filtered or unexported fields
}
func NewLink(link string, maxWorkers int, header map[string]string) *Link

type ProgressStore

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

ProgressStore

	data structure:
		data length      |      8     |       4        |         8            |       8            |
    	data offset      |      0     |       8        |         x            |      x + 8         |
		data description | total size |  block count   |   block start offset |   block end offset |

func (*ProgressStore) Close

func (s *ProgressStore) Close() error

func (*ProgressStore) NewBadIterator

func (s *ProgressStore) NewBadIterator(ctx context.Context) *BlockIterator

func (*ProgressStore) NewIterator

func (s *ProgressStore) NewIterator(ctx context.Context, check checkFunc) *BlockIterator

func (*ProgressStore) NewOkIterator

func (s *ProgressStore) NewOkIterator(ctx context.Context) *BlockIterator

func (*ProgressStore) ReadInt

func (s *ProgressStore) ReadInt(seek int64) (int, error)

func (*ProgressStore) ReadInt64

func (s *ProgressStore) ReadInt64(seek int64) (int64, error)

func (*ProgressStore) WriteInt

func (s *ProgressStore) WriteInt(value int, seek int64) error

func (*ProgressStore) WriteInt64

func (s *ProgressStore) WriteInt64(value int64, seek int64) error

type RandomReadWriter

type RandomReadWriter interface {
	io.WriterAt
	io.ReaderAt
	io.Closer
	Truncate(size int64) error
}

type TaskBlock

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

func (*TaskBlock) FlushAll

func (block *TaskBlock) FlushAll() (err error)

func (*TaskBlock) FlushEnd

func (block *TaskBlock) FlushEnd() (err error)

func (*TaskBlock) FlushStart

func (block *TaskBlock) FlushStart() (err error)

func (*TaskBlock) String

func (block *TaskBlock) String() string

func (*TaskBlock) Write

func (block *TaskBlock) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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