downloader

package
v0.88.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 19 Imported by: 26

Documentation

Overview

Package downloader contains downloading files helpers.

Index

Constants

This section is empty.

Variables

View Source
var ErrHashMismatch = errors.New("file hash mismatch")

ErrHashMismatch means that download hash verification was failed.

Functions

This section is empty.

Types

type Builder added in v0.24.0

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

Builder is a download builder.

func (*Builder) Parallel added in v0.24.0

func (b *Builder) Parallel(ctx context.Context, output io.WriterAt) (tg.StorageFileTypeClass, error)

Parallel downloads file to given io.WriterAt.

func (*Builder) Stream added in v0.24.0

func (b *Builder) Stream(ctx context.Context, output io.Writer) (tg.StorageFileTypeClass, error)

Stream downloads file to given io.Writer. NB: in this mode download can't be parallel.

func (*Builder) ToPath added in v0.24.0

func (b *Builder) ToPath(ctx context.Context, path string) (_ tg.StorageFileTypeClass, err error)

ToPath downloads file to given path.

func (*Builder) WithThreads added in v0.24.0

func (b *Builder) WithThreads(threads int) *Builder

WithThreads sets downloading goroutines limit.

func (*Builder) WithVerify added in v0.24.0

func (b *Builder) WithVerify(verify bool) *Builder

WithVerify sets verify parameter. If verify is true, file hashes will be checked Verify is true by default for CDN downloads.

type CDN added in v0.24.0

type CDN interface {
	UploadGetCDNFile(ctx context.Context, request *tg.UploadGetCDNFileRequest) (tg.UploadCDNFileClass, error)
}

CDN represents Telegram RPC client to CDN server.

type Client added in v0.24.0

type Client interface {
	UploadGetFile(ctx context.Context, request *tg.UploadGetFileRequest) (tg.UploadFileClass, error)
	UploadGetFileHashes(ctx context.Context, request *tg.UploadGetFileHashesRequest) ([]tg.FileHash, error)

	UploadReuploadCDNFile(ctx context.Context, request *tg.UploadReuploadCDNFileRequest) ([]tg.FileHash, error)
	UploadGetCDNFileHashes(ctx context.Context, request *tg.UploadGetCDNFileHashesRequest) ([]tg.FileHash, error)

	UploadGetWebFile(ctx context.Context, request *tg.UploadGetWebFileRequest) (*tg.UploadWebFile, error)
}

Client represents Telegram RPC client.

type Downloader

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

Downloader is Telegram file downloader.

func NewDownloader

func NewDownloader() *Downloader

NewDownloader creates new Downloader.

func (*Downloader) Download

func (d *Downloader) Download(rpc Client, location tg.InputFileLocationClass) *Builder

Download creates Builder for plain downloads.

func (*Downloader) Web added in v0.24.0

func (d *Downloader) Web(rpc Client, location tg.InputWebFileLocationClass) *Builder

Web creates Builder for web files downloads.

func (*Downloader) WithPartSize

func (d *Downloader) WithPartSize(partSize int) *Downloader

WithPartSize sets chunk size. Must be divisible by 4KB.

See https://core.telegram.org/api/files#downloading-files.

type ExpiredTokenError added in v0.24.0

type ExpiredTokenError struct {
	*tg.UploadCDNFileReuploadNeeded
}

ExpiredTokenError error is returned when Downloader get expired file token for CDN. See https://core.telegram.org/constructor/upload.fileCdnRedirect.

func (*ExpiredTokenError) Error added in v0.24.0

func (r *ExpiredTokenError) Error() string

Error implements error interface.

type RedirectError

type RedirectError struct {
	Redirect *tg.UploadFileCDNRedirect
}

RedirectError error is returned when Downloader get CDN redirect. See https://core.telegram.org/constructor/upload.fileCdnRedirect.

func (*RedirectError) Error

func (r *RedirectError) Error() string

Error implements error interface.

Jump to

Keyboard shortcuts

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