Documentation
¶
Overview ¶
Package downloader contains downloading files helpers.
Index ¶
- Constants
- Variables
- type Builder
- func (b *Builder) Parallel(ctx context.Context, output io.WriterAt) (_ tg.StorageFileTypeClass, err error)
- func (b *Builder) Stream(ctx context.Context, output io.Writer) (_ tg.StorageFileTypeClass, err error)
- func (b *Builder) ToPath(ctx context.Context, path string) (_ tg.StorageFileTypeClass, err error)
- func (b *Builder) WithRetryHandler(handler RetryHandler) *Builder
- func (b *Builder) WithThreads(threads int) *Builder
- func (b *Builder) WithVerify(verify bool) *Builder
- type CDN
- type CDNProvider
- type Client
- type Downloader
- func (d *Downloader) Download(rpc Client, location tg.InputFileLocationClass) *Builder
- func (d *Downloader) Web(rpc Client, location tg.InputWebFileLocationClass) *Builder
- func (d *Downloader) WithAllowCDN(allow bool) *Downloader
- func (d *Downloader) WithPartSize(partSize int) *Downloader
- func (d *Downloader) WithRetryHandler(handler RetryHandler) *Downloader
- type RedirectError
- type RetryEvent
- type RetryHandler
Constants ¶
const ( RetryOperationGetFile = "cdn.get_file" RetryOperationGetFileHashes = "cdn.get_file_hashes" RetryOperationReupload = "cdn.reupload" RetryOperationRefreshRedirect = "cdn.refresh_redirect" RetryOperationCreateClient = "cdn.create_client" RetryOperationReaderChunk = "reader.chunk" RetryOperationReaderHashes = "reader.hashes" )
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, err 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, err error)
Stream downloads file to given io.Writer. NB: in this mode download can't be parallel.
func (*Builder) WithRetryHandler ¶ added in v0.142.0
func (b *Builder) WithRetryHandler(handler RetryHandler) *Builder
WithRetryHandler sets callback for transient download errors that are retried internally.
Handler can be called concurrently from download workers.
func (*Builder) WithThreads ¶ added in v0.24.0
WithThreads sets downloading goroutines limit.
func (*Builder) WithVerify ¶ added in v0.24.0
WithVerify controls global hash verification behavior.
`true` enables classic verifier reader (preloads hash queue and validates all chunks, both legacy and CDN). `false` disables classic verifier reader.
If not called explicitly: - non-CDN path preserves old behavior (no upfront hash requests); - CDN path enables strict inline CDN verification after redirect.
Use WithVerify(true) to force verifier-queue mode on all paths.
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 CDNProvider ¶ added in v0.142.0
CDNProvider creates client bound to requested CDN DC. Returned closer is schema-scoped; for shared client-level pool adapters this can be a no-op closer.
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) WithAllowCDN ¶ added in v0.142.0
func (d *Downloader) WithAllowCDN(allow bool) *Downloader
WithAllowCDN explicitly enables or disables CDN redirect flow.
This flag is explicit: if it is not set, downloader keeps legacy master-DC-only behavior and does not attempt CDN redirect handling. Client integration (`telegram.Client.Downloader`) sets this option from `telegram.Options.AllowCDN`.
func (*Downloader) WithPartSize ¶
func (d *Downloader) WithPartSize(partSize int) *Downloader
WithPartSize sets chunk size. Must be divisible by 4KB.
func (*Downloader) WithRetryHandler ¶ added in v0.142.0
func (d *Downloader) WithRetryHandler(handler RetryHandler) *Downloader
WithRetryHandler sets callback for transient download errors that are retried internally by downloader.
Handler can be called concurrently from download workers.
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.
type RetryEvent ¶ added in v0.142.0
type RetryEvent struct {
// Operation identifies retry source.
Operation string
// Attempt is 1-based counter inside current retry loop.
Attempt int
// Err is the error that triggered retry.
Err error
}
RetryEvent describes retried transient downloader error.
type RetryHandler ¶ added in v0.142.0
type RetryHandler func(event RetryEvent)
RetryHandler is called for every downloader error that is retried internally.