download

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: GPL-3.0 Imports: 19 Imported by: 3

Documentation

Index

Constants

View Source
const (
	EventKeyStart    = "start"
	EventKeyPause    = "pause"
	EventKeyContinue = "continue"
	EventKeyProgress = "progress"
	EventKeyError    = "error"
	EventKeyDelete   = "delete"
	EventKeyDone     = "done"
	EventKeyFinally  = "finally"
)

Variables

This section is empty.

Functions

func Boot

func Boot() *boot

Types

type BoltStorage

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

func NewBoltStorage

func NewBoltStorage(dir string) *BoltStorage

func (*BoltStorage) Clear

func (b *BoltStorage) Clear() error

func (*BoltStorage) Close

func (b *BoltStorage) Close() error

func (*BoltStorage) Delete

func (b *BoltStorage) Delete(bucket string, key string) error

func (*BoltStorage) Get

func (b *BoltStorage) Get(bucket string, key string, v any) (bool, error)

func (*BoltStorage) List

func (b *BoltStorage) List(bucket string, v any) error

func (*BoltStorage) Pop

func (b *BoltStorage) Pop(bucket string, key string, v any) error

func (*BoltStorage) Put

func (b *BoltStorage) Put(bucket string, key string, v any) error

func (*BoltStorage) Setup

func (b *BoltStorage) Setup(buckets []string) error

type Downloader

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

func NewDownloader

func NewDownloader(cfg *DownloaderConfig) *Downloader

func (*Downloader) Clear

func (d *Downloader) Clear() error

func (*Downloader) Close

func (d *Downloader) Close() error

func (*Downloader) Continue

func (d *Downloader) Continue(id string) (err error)

func (*Downloader) Create

func (d *Downloader) Create(rrId string, opts *base.Options) (taskId string, err error)

func (*Downloader) CreateDirect added in v1.3.1

func (d *Downloader) CreateDirect(req *base.Request, opts *base.Options) (taskId string, err error)

func (*Downloader) Delete

func (d *Downloader) Delete(id string, force bool) (err error)

func (*Downloader) GetConfig

func (d *Downloader) GetConfig() (*DownloaderStoreConfig, error)

func (*Downloader) GetTask

func (d *Downloader) GetTask(id string) *Task

func (*Downloader) GetTasks

func (d *Downloader) GetTasks() []*Task

func (*Downloader) Listener

func (d *Downloader) Listener(fn Listener)

func (*Downloader) Pause

func (d *Downloader) Pause(id string) (err error)

func (*Downloader) PutConfig

func (d *Downloader) PutConfig(v *DownloaderStoreConfig) error

func (*Downloader) Resolve

func (d *Downloader) Resolve(req *base.Request) (rr *ResolveResult, err error)

func (*Downloader) Setup

func (d *Downloader) Setup() error

type DownloaderConfig

type DownloaderConfig struct {
	Controller    *controller.Controller
	FetchBuilders []fetcher.FetcherBuilder

	RefreshInterval int `json:"refreshInterval"` // RefreshInterval time duration to refresh task progress(ms)
	Storage         Storage

	*DownloaderStoreConfig
}

func (*DownloaderConfig) Init

func (cfg *DownloaderConfig) Init() *DownloaderConfig

type DownloaderStoreConfig

type DownloaderStoreConfig struct {
	FirstLoad bool `json:"-"` // fromNoStore is the flag that the config is first time init and not from store

	DownloadDir    string         `json:"downloadDir"`    // DownloadDir is the default directory to save the downloaded files
	MaxRunning     int            `json:"maxRunning"`     // MaxRunning is the max running download count
	ProtocolConfig map[string]any `json:"protocolConfig"` // ProtocolConfig is special config for each protocol
	Extra          map[string]any `json:"extra"`          // Extra is the extra config
}

DownloaderStoreConfig is the config that can restore the downloader.

func (*DownloaderStoreConfig) Init added in v1.3.1

type Event

type Event struct {
	Key  EventKey
	Task *Task
	Err  error
}

type EventKey

type EventKey string

type Listener

type Listener func(event *Event)

type MemStorage

type MemStorage struct {
}

func NewMemStorage

func NewMemStorage() *MemStorage

func (*MemStorage) Clear

func (n *MemStorage) Clear() error

func (*MemStorage) Close

func (n *MemStorage) Close() error

func (*MemStorage) Delete

func (n *MemStorage) Delete(bucket string, key string) error

func (*MemStorage) Get

func (n *MemStorage) Get(bucket string, key string, v any) (bool, error)

func (*MemStorage) List

func (n *MemStorage) List(bucket string, v any) error

func (*MemStorage) Pop

func (n *MemStorage) Pop(bucket string, key string, v any) error

func (*MemStorage) Put

func (n *MemStorage) Put(bucket string, key string, v any) error

func (*MemStorage) Setup

func (n *MemStorage) Setup(buckets []string) error

type Progress

type Progress struct {
	// 下载耗时(纳秒)
	Used int64 `json:"used"`
	// 每秒下载字节数
	Speed int64 `json:"speed"`
	// 已下载的字节数
	Downloaded int64 `json:"downloaded"`
}

type ResolveResult

type ResolveResult struct {
	ID  string         `json:"id"`
	Res *base.Resource `json:"res"`
}

type Storage

type Storage interface {
	Setup(buckets []string) error
	Put(bucket string, key string, v any) error
	Get(bucket string, key string, v any) (bool, error)
	List(bucket string, v any) error
	Pop(bucket string, key string, v any) error
	Delete(bucket string, key string) error

	Close() error
	Clear() error
}

type Task

type Task struct {
	ID        string               `json:"id"`
	Meta      *fetcher.FetcherMeta `json:"meta"`
	Status    base.Status          `json:"status"`
	Progress  *Progress            `json:"progress"`
	Size      int64                `json:"size"`
	CreatedAt time.Time            `json:"createdAt"`
	// contains filtered or unexported fields
}

func NewTask

func NewTask() *Task

Jump to

Keyboard shortcuts

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