add demo downloading

This commit is contained in:
Robin Appelman 2022-04-30 19:52:38 +02:00
commit bdd8ec590a
2 changed files with 18 additions and 1 deletions

View file

@ -12,10 +12,12 @@ exclude = [ "tests/data/gully.dem" ]
[dependencies]
serde = { version = "1", features = ["derive"] }
time = { version = "0.3", features = ["serde"] }
reqwest = { version = "0.11", default-features = false, features = ["json", "multipart"] }
reqwest = { version = "0.11", default-features = false, features = ["json", "multipart", "stream"] }
thiserror = "1"
hex = "0.4"
steamid-ng = "1"
bytes = "1.1.0"
futures-util = "0.3.21"
[dev-dependencies]
tokio = { version = "1", features = ["macros"] }

View file

@ -1,3 +1,5 @@
use bytes::Bytes;
use futures_util::{Stream, StreamExt};
use reqwest::{multipart, Client, IntoUrl, StatusCode, Url};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::Cow;
@ -64,6 +66,19 @@ impl Demo {
Ok(Cow::Owned(demo.players))
}
}
pub async fn download(
&self,
client: &ApiClient,
) -> Result<impl Stream<Item = Result<Bytes, Error>>, Error> {
Ok(client
.client
.get(&self.url)
.send()
.await?
.bytes_stream()
.map(|chunk| Ok(chunk?)))
}
}
/// Reference to a user, either contains the full user information or only the user id