// Package downloader contains downloading files helpers.
package downloader import ( ) // Downloader is Telegram file downloader. type Downloader struct { partSize int pool *bin.Pool // allowCDN is tri-state: // nil -> keep default downloader behavior (CDN disabled), // true -> allow redirect flow, // false-> force legacy master-only flow. allowCDN *bool // retryHandler observes transient downloader errors that are retried. retryHandler RetryHandler } const defaultPartSize = 512 * 1024 // 512 kb // NewDownloader creates new Downloader. func () *Downloader { return new(Downloader).WithPartSize(defaultPartSize) } // WithPartSize sets chunk size. // Must be divisible by 4KB. // // See https://core.telegram.org/api/files#downloading-files. func ( *Downloader) ( int) *Downloader { .partSize = .pool = bin.NewPool() return } // 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) ( bool) *Downloader { .allowCDN = & return } // WithRetryHandler sets callback for transient download errors that are retried // internally by downloader. // // Handler can be called concurrently from download workers. func ( *Downloader) ( RetryHandler) *Downloader { .retryHandler = return } // Download creates Builder for plain downloads. func ( *Downloader) ( Client, tg.InputFileLocationClass) *Builder { return newBuilder(, master{ client: , precise: true, allowCDN: false, retryHandler: .retryHandler, location: , }) } // Web creates Builder for web files downloads. func ( *Downloader) ( Client, tg.InputWebFileLocationClass) *Builder { return newBuilder(, web{ client: , retryHandler: .retryHandler, location: , }) }