Documentation
¶
Overview ¶
Пакет dl содержит абстракции для загрузки файлов и каталогов из различных источников.
Index ¶
- Variables
- func Download(ctx context.Context, opts Options) (err error)
- func HashLocal(path string, h hash.Hash) error
- func IsLocalUrl(u *url.URL) bool
- func VerifyHashFromLocal(path string, opts Options) error
- type Downloader
- type FileDownloader
- type GitDownloader
- type Manifest
- type Options
- type ProgressWriter
- type TorrentDownloader
- type Type
- type UpdatingDownloader
Constants ¶
This section is empty.
Variables ¶
var ( ErrChecksumMismatch = errors.New("dl: checksums did not match") ErrNoSuchHashAlgo = errors.New("dl: invalid hashing algorithm") )
Объявление ошибок для несоответствия контрольной суммы и отсутствия алгоритма хеширования
var ( ErrAria2NotFound = errors.New("aria2 must be installed for torrent functionality") ErrDestinationEmpty = errors.New("the destination directory is empty") )
var Downloaders = []Downloader{ &GitDownloader{}, TorrentDownloader{}, FileDownloader{}, }
Массив доступных загрузчиков в порядке их проверки
Functions ¶
func Download ¶
Download handles downloading a file or directory with the given options.
func HashLocal ¶
HashLocal hashes a file or directory using the provided hash function.
Types ¶
type Downloader ¶
type Downloader interface {
Name() string
MatchURL(string) bool
Download(context.Context, Options) (Type, string, error)
}
Интерфейс Downloader для реализации различных загрузчиков
type FileDownloader ¶
type FileDownloader struct{}
FileDownloader загружает файлы с использованием HTTP
func (FileDownloader) Download ¶
Download downloads a file using HTTP. If the file is compressed in a supported format, it will be unpacked.
func (FileDownloader) MatchURL ¶
func (FileDownloader) MatchURL(string) bool
MatchURL всегда возвращает true, так как FileDownloader используется как резерв, если ничего другого не соответствует
type GitDownloader ¶
type GitDownloader struct{}
GitDownloader downloads Git repositories
func (*GitDownloader) Download ¶
Download uses git to clone the repository from the specified URL. It allows specifying the revision, depth and recursion options via query string
func (GitDownloader) MatchURL ¶
func (GitDownloader) MatchURL(u string) bool
MatchURL matches any URLs that start with "git+"
func (*GitDownloader) Update ¶
func (d *GitDownloader) Update(opts Options) (bool, error)
Update uses git to pull the repository and update it to the latest revision. It allows specifying the depth and recursion options via query string. It returns true if update was successful and false if the repository is already up-to-date
type Manifest ¶
Структура Manifest хранит информацию о типе и имени загруженного файла или каталога
type Options ¶
type Options struct {
Hash []byte
HashAlgorithm string
Name string
URL string
Destination string
CacheDisabled bool
PostprocDisabled bool
Progress io.Writer
LocalDir string
DlCache cache.DlCache
CacheMetadata cache.Metadata
Output output.Output
NewExtractor bool
}
Структура Options содержит параметры для загрузки файлов и каталогов
type ProgressWriter ¶
type ProgressWriter struct {
// contains filtered or unexported fields
}
func NewProgressWriter ¶
func NewProgressWriter(ctx context.Context, base io.WriteCloser, max int64, filename string, out io.Writer) *ProgressWriter
func (*ProgressWriter) Close ¶
func (pw *ProgressWriter) Close() error
func (*ProgressWriter) Write ¶
func (pw *ProgressWriter) Write(p []byte) (int, error)
type TorrentDownloader ¶
type TorrentDownloader struct{}
func (TorrentDownloader) Download ¶
Download downloads a file over the BitTorrent protocol.
func (TorrentDownloader) MatchURL ¶
func (TorrentDownloader) MatchURL(u string) bool
MatchURL returns true if the URL is a magnet link or an http(s) link with a "torrent+" prefix
type UpdatingDownloader ¶
type UpdatingDownloader interface {
Downloader
Update(Options) (bool, error)
}
Интерфейс UpdatingDownloader расширяет Downloader методом Update
Source Files
¶
- dl.go
- file.go
- git.go
- progress_tui.go
- torrent.go
- utils.go