Documentation ¶
Overview ¶
Package downloader contains downloading files helpers.
Index ¶
- Variables
- type Builder
- func (b *Builder) Parallel(ctx context.Context, output io.WriterAt) (tg.StorageFileTypeClass, error)
- func (b *Builder) Stream(ctx context.Context, output io.Writer) (tg.StorageFileTypeClass, error)
- func (b *Builder) ToPath(ctx context.Context, path string) (_ tg.StorageFileTypeClass, err error)
- func (b *Builder) WithThreads(threads int) *Builder
- func (b *Builder) WithVerify(verify bool) *Builder
- type CDN
- type Client
- type Downloader
- type ExpiredTokenError
- type RedirectError
Constants ¶
This section is empty.
Variables ¶
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
Stream downloads file to given io.Writer. NB: in this mode download can't be parallel.
func (*Builder) WithThreads ¶ added in v0.24.0
WithThreads sets downloading goroutines limit.
func (*Builder) WithVerify ¶ added in v0.24.0
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 (*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.
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.