pub trait Download<'w> {
    type Err;
    type Fut: Future<Output = Result<(), Self::Err>> + Send;
    type StreamErr;
    type Stream: Stream<Item = Result<Bytes, Self::StreamErr>> + Send;

    // Required methods
    fn download_file(
        &self,
        path: &str,
        destination: &'w mut (dyn AsyncWrite + Unpin + Send)
    ) -> Self::Fut;
    fn download_file_stream(&self, path: &str) -> Self::Stream;
}
Expand description

A trait for downloading files from Telegram.

Required Associated Types§

source

type Err

An error returned from download_file.

source

type Fut: Future<Output = Result<(), Self::Err>> + Send

A future returned from download_file.

source

type StreamErr

An error returned from download_file_stream.

source

type Stream: Stream<Item = Result<Bytes, Self::StreamErr>> + Send

A stream returned from download_file_stream.

Required Methods§

source

fn download_file( &self, path: &str, destination: &'w mut (dyn AsyncWrite + Unpin + Send) ) -> Self::Fut

Download a file from Telegram into destination.

path can be obtained from GetFile.

To download as a stream of chunks, see download_file_stream.

Examples
use teloxide_core::{
    net::Download,
    requests::{Request, Requester},
    types::File,
    Bot,
};
use tokio::fs;

let bot = Bot::new("TOKEN");

let file = bot.get_file("*file_id*").await?;
let mut dst = fs::File::create("/tmp/test.png").await?;
bot.download_file(&file.path, &mut dst).await?;
source

fn download_file_stream(&self, path: &str) -> Self::Stream

Download a file from Telegram as [Stream].

path can be obtained from the GetFile.

To download into an AsyncWrite (e.g. tokio::fs::File), see download_file.

Implementors§

source§

impl<'w> Download<'w> for Bot

§

type Err = DownloadError

§

type Fut = Pin<Box<dyn Future<Output = Result<(), DownloadError>> + Send + 'w, Global>>

§

type StreamErr = Error

§

type Stream = Pin<Box<dyn Stream<Item = Result<Bytes, Error>> + Send + 'static, Global>>

source§

impl<'w, B: Download<'w>> Download<'w> for AutoSend<B>

Available on crate feature auto_send only.
§

type Err = <B as Download<'w>>::Err

§

type Fut = <B as Download<'w>>::Fut

§

type StreamErr = <B as Download<'w>>::StreamErr

§

type Stream = <B as Download<'w>>::Stream

source§

impl<'w, B: Download<'w>> Download<'w> for CacheMe<B>

Available on crate feature cache_me only.
§

type Err = <B as Download<'w>>::Err

§

type Fut = <B as Download<'w>>::Fut

§

type StreamErr = <B as Download<'w>>::StreamErr

§

type Stream = <B as Download<'w>>::Stream

source§

impl<'w, B: Download<'w>> Download<'w> for DefaultParseMode<B>

§

type Err = <B as Download<'w>>::Err

§

type Fut = <B as Download<'w>>::Fut

§

type StreamErr = <B as Download<'w>>::StreamErr

§

type Stream = <B as Download<'w>>::Stream

source§

impl<'w, B: Download<'w>> Download<'w> for Throttle<B>

Available on crate feature throttle only.
§

type Err = <B as Download<'w>>::Err

§

type Fut = <B as Download<'w>>::Fut

§

type StreamErr = <B as Download<'w>>::StreamErr

§

type Stream = <B as Download<'w>>::Stream