dl

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: GPL-3.0 Imports: 42 Imported by: 1

Documentation

Overview

Пакет dl содержит абстракции для загрузки файлов и каталогов из различных источников.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrChecksumMismatch = errors.New("dl: checksums did not match")
	ErrNoSuchHashAlgo   = errors.New("dl: invalid hashing algorithm")
)

Объявление ошибок для несоответствия контрольной суммы и отсутствия алгоритма хеширования

View Source
var (
	ErrAria2NotFound    = errors.New("aria2 must be installed for torrent functionality")
	ErrDestinationEmpty = errors.New("the destination directory is empty")
)
View Source
var Downloaders = []Downloader{
	&GitDownloader{},
	TorrentDownloader{},
	FileDownloader{},
}

Массив доступных загрузчиков в порядке их проверки

Functions

func Download

func Download(ctx context.Context, opts Options) (err error)

Download handles downloading a file or directory with the given options.

func HashLocal

func HashLocal(path string, h hash.Hash) error

HashLocal hashes a file or directory using the provided hash function.

func IsLocalUrl added in v0.0.27

func IsLocalUrl(u *url.URL) bool

func VerifyHashFromLocal

func VerifyHashFromLocal(path string, opts Options) error

If the checksum does not match, returns ErrChecksumMismatch

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

func (fd FileDownloader) Download(ctx context.Context, opts Options) (Type, string, error)

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 используется как резерв, если ничего другого не соответствует

func (FileDownloader) Name

func (FileDownloader) Name() string

Name всегда возвращает "file"

type GitDownloader

type GitDownloader struct{}

GitDownloader downloads Git repositories

func (*GitDownloader) Download

func (d *GitDownloader) Download(ctx context.Context, opts Options) (Type, string, error)

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) Name

func (GitDownloader) Name() string

Name always returns "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

type Manifest struct {
	Type Type
	Name string
}

Структура 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 содержит параметры для загрузки файлов и каталогов

func (Options) NewHash

func (opts Options) NewHash() (hash.Hash, error)

Метод для создания нового хеша на основе указанного алгоритма хеширования

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

func (TorrentDownloader) Download(ctx context.Context, opts Options) (Type, string, error)

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

func (TorrentDownloader) Name

func (TorrentDownloader) Name() string

Name always returns "file"

type Type

type Type uint8

Тип данных, представляющий тип загрузки (файл или каталог)

const (
	TypeFile Type = iota
	TypeDir
)

Объявление констант для типов загрузки

func (Type) String

func (t Type) String() string

Метод для получения строки, представляющей тип загрузки

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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