mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-09 01:50:30 +00:00
feat: reuse fetcher (#71)
This commit is contained in:
1 parent
17cb59c606
commit
1a3c8c026b
36 files changed
+475
-297
No files matched your search
@@ -6,24 +6,34 @@ import (
|
||||
)
|
||||
|
||||
// Fetcher defines the interface for a download protocol.
|
||||
// One fetcher for each download task
|
||||
type Fetcher interface {
|
||||
// Name return the name of the protocol.
|
||||
Name() string
|
||||
|
||||
Setup(ctl *controller.Controller) error
|
||||
// Resolve resource info from request
|
||||
Resolve(req *base.Request) (res *base.Resource, err error)
|
||||
Resolve(req *base.Request) error
|
||||
// Create ready to download, but not started
|
||||
Create(res *base.Resource, opts *base.Options) (err error)
|
||||
Start() (err error)
|
||||
Pause() (err error)
|
||||
Continue() (err error)
|
||||
Close() (err error)
|
||||
Create(opts *base.Options) error
|
||||
Start() error
|
||||
Pause() error
|
||||
Continue() error
|
||||
Close() error
|
||||
|
||||
// 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() (err error)
|
||||
Wait() error
|
||||
}
|
||||
|
||||
// FetcherMeta defines the meta information of a fetcher.
|
||||
type FetcherMeta struct {
|
||||
Req *base.Request `json:"req"`
|
||||
Res *base.Resource `json:"res"`
|
||||
Opts *base.Options `json:"opts"`
|
||||
}
|
||||
|
||||
// FetcherBuilder defines the interface for a fetcher builder.
|
||||
@@ -36,11 +46,12 @@ type FetcherBuilder interface {
|
||||
// Store fetcher
|
||||
Store(fetcher Fetcher) (any, error)
|
||||
// Restore fetcher
|
||||
Restore() (v any, f func(res *base.Resource, opts *base.Options, v any) Fetcher)
|
||||
Restore() (v any, f func(meta *FetcherMeta, v any) Fetcher)
|
||||
}
|
||||
|
||||
type DefaultFetcher struct {
|
||||
Ctl *controller.Controller
|
||||
Meta *FetcherMeta
|
||||
DoneCh chan error
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user