mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-24 09:16:12 +01:00
Merge pull request #44 from async-telegram-bot/feature_gate_unstable_stream
Add "unstable-stream" feature
This commit is contained in:
commit
e3873ca3b4
4 changed files with 29 additions and 11 deletions
|
@ -15,3 +15,8 @@ tokio = "0.2.0-alpha.6"
|
||||||
bytes = "0.4.12"
|
bytes = "0.4.12"
|
||||||
futures-preview = "0.3.0-alpha.19"
|
futures-preview = "0.3.0-alpha.19"
|
||||||
async-trait = "0.1.13"
|
async-trait = "0.1.13"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
|
||||||
|
unstable-stream = [] # add streams to public API
|
|
@ -1,11 +1,17 @@
|
||||||
use tokio::{io::AsyncWrite, stream::Stream};
|
use tokio::io::AsyncWrite;
|
||||||
use bytes::Bytes;
|
#[cfg(feature = "unstable-stream")]
|
||||||
|
use ::{
|
||||||
|
bytes::Bytes,
|
||||||
|
tokio::stream::Stream,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bot::Bot,
|
bot::Bot,
|
||||||
network::{download_file, download_file_stream},
|
|
||||||
DownloadError,
|
DownloadError,
|
||||||
|
network::download_file,
|
||||||
};
|
};
|
||||||
|
#[cfg(feature = "unstable-stream")]
|
||||||
|
use crate::network::download_file_stream;
|
||||||
|
|
||||||
impl Bot {
|
impl Bot {
|
||||||
/// Download file from telegram into `destination`.
|
/// Download file from telegram into `destination`.
|
||||||
|
@ -56,6 +62,7 @@ impl Bot {
|
||||||
/// [`AsyncWrite`]: tokio::io::AsyncWrite
|
/// [`AsyncWrite`]: tokio::io::AsyncWrite
|
||||||
/// [`tokio::fs::File`]: tokio::fs::File
|
/// [`tokio::fs::File`]: tokio::fs::File
|
||||||
/// [`download_file`]: crate::bot::Bot::download_file
|
/// [`download_file`]: crate::bot::Bot::download_file
|
||||||
|
#[cfg(feature = "unstable-stream")]
|
||||||
pub async fn download_file_stream(
|
pub async fn download_file_stream(
|
||||||
&self,
|
&self,
|
||||||
path: &str,
|
path: &str,
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use bytes::Bytes;
|
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use tokio::{
|
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||||
io::{AsyncWrite, AsyncWriteExt},
|
#[cfg(feature = "unstable-stream")]
|
||||||
stream::Stream,
|
use ::{
|
||||||
|
tokio::stream::Stream,
|
||||||
|
bytes::Bytes,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::DownloadError;
|
use crate::DownloadError;
|
||||||
|
@ -31,6 +32,7 @@ where
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-stream")]
|
||||||
pub async fn download_file_stream(
|
pub async fn download_file_stream(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
token: &str,
|
token: &str,
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
pub use download::{download_file, download_file_stream};
|
pub use self::{
|
||||||
pub use request::{request_json, request_multipart};
|
download::download_file,
|
||||||
pub use telegram_response::TelegramResponse;
|
request::{request_json, request_multipart},
|
||||||
|
telegram_response::TelegramResponse,
|
||||||
|
};
|
||||||
|
#[cfg(feature = "unstable-stream")]
|
||||||
|
pub use download::download_file_stream;
|
||||||
|
|
||||||
mod download;
|
mod download;
|
||||||
mod request;
|
mod request;
|
||||||
|
@ -22,7 +26,7 @@ fn method_url(base: &str, token: &str, method_name: &str) -> String {
|
||||||
|
|
||||||
/// Creates URL for downloading a file. See the [Telegram documentation].
|
/// Creates URL for downloading a file. See the [Telegram documentation].
|
||||||
///
|
///
|
||||||
/// [Telegram documentation] (https://core.telegram.org/bots/api#file)
|
/// [Telegram documentation]: https://core.telegram.org/bots/api#file
|
||||||
fn file_url(base: &str, token: &str, file_path: &str) -> String {
|
fn file_url(base: &str, token: &str, file_path: &str) -> String {
|
||||||
format!(
|
format!(
|
||||||
"{url}/file/bot{token}/{file}",
|
"{url}/file/bot{token}/{file}",
|
||||||
|
|
Loading…
Add table
Reference in a new issue