Documentation ¶
Index ¶
- Constants
- Variables
- func MergeBlocks(blocks []*TaskBlock) (err error)
- func RecoverApplyFunc(f func())
- func RecoverGoroutine(f func())
- func ResolveContentRange(contentRange string) (int64, error)
- func ResolveFileSize(httpClient *http.Client, link *Link) (int64, error)
- type BlockIterator
- type DownloadHandler
- type DownloadProcessor
- type DownloadTask
- func (t *DownloadTask) Close()
- func (t *DownloadTask) Done() <-chan struct{}
- func (t *DownloadTask) GetCompletedSize() (int64, error)
- func (t *DownloadTask) GetError() error
- func (t *DownloadTask) GetSize() int64
- func (t *DownloadTask) GetStatus() string
- func (t *DownloadTask) GetStatusInfo() *DownloadTaskStatus
- func (t *DownloadTask) GetThreadCount() int32
- func (t *DownloadTask) GetTotalDownload() int64
- func (t *DownloadTask) Run()
- type DownloadTaskOptionsBuilder
- func (o *DownloadTaskOptionsBuilder) Build(links ...*Link) (DownloadTaskOptionsProvider, error)
- func (o *DownloadTaskOptionsBuilder) SetClient(c *http.Client)
- func (o *DownloadTaskOptionsBuilder) SetDataStore(dataStore RandomReadWriter)
- func (o *DownloadTaskOptionsBuilder) SetDataStoreByPath(file string) (err error)
- func (o *DownloadTaskOptionsBuilder) SetHttpClient(httpClient *http.Client)
- func (o *DownloadTaskOptionsBuilder) SetMaxBlockSize(maxBlockSize int)
- func (o *DownloadTaskOptionsBuilder) SetMinBlockSize(minBlockSize int)
- func (o *DownloadTaskOptionsBuilder) SetProgressStore(progressStore RandomReadWriter)
- func (o *DownloadTaskOptionsBuilder) SetProgressStoreByPath(file string) (err error)
- func (o *DownloadTaskOptionsBuilder) SetSize(size int64)
- func (o *DownloadTaskOptionsBuilder) SetStatusUpdateInterval(duration time.Duration)
- type DownloadTaskOptionsProvider
- type DownloadTaskStatus
- type HandlerWatcher
- type Link
- type ProgressStore
- func (s *ProgressStore) Close() error
- func (s *ProgressStore) NewBadIterator(ctx context.Context) *BlockIterator
- func (s *ProgressStore) NewIterator(ctx context.Context, check checkFunc) *BlockIterator
- func (s *ProgressStore) NewOkIterator(ctx context.Context) *BlockIterator
- func (s *ProgressStore) ReadInt(seek int64) (int, error)
- func (s *ProgressStore) ReadInt64(seek int64) (int64, error)
- func (s *ProgressStore) WriteInt(value int, seek int64) error
- func (s *ProgressStore) WriteInt64(value int64, seek int64) error
- type RandomReadWriter
- type TaskBlock
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 RecoverApplyFunc ¶
func RecoverApplyFunc(f func())
func RecoverGoroutine ¶
func RecoverGoroutine(f func())
func ResolveContentRange ¶
Types ¶
type BlockIterator ¶
type BlockIterator struct {
// contains filtered or unexported fields
}
func (*BlockIterator) Next ¶
func (it *BlockIterator) Next() (*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) 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
type DownloadTaskOptionsBuilder ¶
type DownloadTaskOptionsBuilder struct {
// contains filtered or unexported fields
}
func NewDownloadTaskOptionsBuilder ¶
func NewDownloadTaskOptionsBuilder() *DownloadTaskOptionsBuilder
func (*DownloadTaskOptionsBuilder) Build ¶
func (o *DownloadTaskOptionsBuilder) Build(links ...*Link) (DownloadTaskOptionsProvider, error)
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 HandlerWatcher ¶
type HandlerWatcher func(in bool)
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) WriteInt64 ¶
func (s *ProgressStore) WriteInt64(value int64, seek int64) error
type RandomReadWriter ¶
type TaskBlock ¶
type TaskBlock struct {
// contains filtered or unexported fields
}
func (*TaskBlock) FlushStart ¶
Click to show internal directories.
Click to hide internal directories.