fetcher

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultFetcher

type DefaultFetcher struct {
	Ctl    *controller.Controller
	Meta   *FetcherMeta
	DoneCh chan error
}

func (*DefaultFetcher) Setup

func (f *DefaultFetcher) Setup(ctl *controller.Controller) (err error)

func (*DefaultFetcher) Wait

func (f *DefaultFetcher) Wait() (err error)

type Fetcher

type Fetcher interface {
	Setup(ctl *controller.Controller)
	// Resolve resource info from request
	Resolve(req *base.Request) error
	// Create ready to download, but not started
	Create(opts *base.Options) error
	Start() error
	Pause() error
	Close() error

	// Stats refreshes health statistics and returns the latest information
	Stats() any
	// Meta returns the meta information of the download.
	Meta() *FetcherMeta
	// Progress returns the progress of the download.
	Progress() Progress
	// Wait for the download to complete, this method will block until the download is done.
	Wait() error
}

Fetcher defines the interface for a download protocol. Each download task will have a corresponding Fetcher instance for the management of the download task

type FetcherManager added in v1.5.8

type FetcherManager interface {
	// Name return the name of the protocol.
	Name() string
	// Filters registers the supported schemes.
	Filters() []*SchemeFilter
	// Build returns a new fetcher.
	Build() Fetcher
	// ParseName name displayed when the task is not yet resolved, parsed from the request URL
	ParseName(u string) string
	// AutoRename returns whether the fetcher need renaming the download file when has the same name file.
	AutoRename() bool

	// DefaultConfig returns the default configuration of the protocol.
	DefaultConfig() any
	// Store fetcher
	Store(fetcher Fetcher) (any, error)
	// Restore fetcher
	Restore() (v any, f func(meta *FetcherMeta, v any) Fetcher)
	// Close the fetcher manager, release resources.
	Close() error
}

FetcherManager manage and control the fetcher

type FetcherMeta

type FetcherMeta struct {
	Req  *base.Request  `json:"req"`
	Res  *base.Resource `json:"res"`
	Opts *base.Options  `json:"opts"`
}

FetcherMeta defines the meta information of a fetcher.

func (*FetcherMeta) FolderPath added in v1.4.0

func (m *FetcherMeta) FolderPath() string

FolderPath return the folder path of the meta info.

func (*FetcherMeta) RootDirPath added in v1.5.0

func (m *FetcherMeta) RootDirPath() string

RootDirPath return the root dir path of the task file.

func (*FetcherMeta) SingleFilepath added in v1.4.0

func (m *FetcherMeta) SingleFilepath() string

SingleFilepath return the single file path of the meta info.

type FilterType added in v1.5.8

type FilterType int
const (
	// FilterTypeUrl url type, pattern is the scheme, e.g. http://github.com -> http
	FilterTypeUrl FilterType = iota
	// FilterTypeFile file type, pattern is the file extension name, e.g. test.torrent -> torrent
	FilterTypeFile
	// FilterTypeBase64 base64 data type, pattern is the data mime type, e.g. data:application/x-bittorrent;base64 -> application/x-bittorrent
	FilterTypeBase64
)

type Progress

type Progress []int64

Progress is a map of the progress of each file in the torrent.

func (Progress) TotalDownloaded

func (p Progress) TotalDownloaded() int64

TotalDownloaded returns the total downloaded bytes.

type SchemeFilter added in v1.5.8

type SchemeFilter struct {
	Type    FilterType
	Pattern string
}

func (*SchemeFilter) Match added in v1.5.8

func (s *SchemeFilter) Match(uri string) bool

type Uploader added in v1.5.8

type Uploader interface {
	Upload() error
	UploadedBytes() int64
	WaitUpload() error
}

Jump to

Keyboard shortcuts

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