Struct modio::download::Downloader
source · pub struct Downloader(/* private fields */);
Expand description
A Downloader
can be used to stream a mod file or save the file to a local file.
Constructed with Modio::download
.
Implementations§
source§impl Downloader
impl Downloader
sourcepub async fn save_to_file<P: AsRef<Path>>(self, file: P) -> Result<()>
pub async fn save_to_file<P: AsRef<Path>>(self, file: P) -> Result<()>
Save the mod file to a local file.
§Example
let action = modio::DownloadAction::Primary {
game_id: Id::new(5),
mod_id: Id::new(19),
};
modio
.download(action)
.await?
.save_to_file("mod.zip")
.await?;
sourcepub async fn bytes(self) -> Result<Bytes>
pub async fn bytes(self) -> Result<Bytes>
Get the full mod file as Bytes
.
§Example
let action = modio::DownloadAction::Primary {
game_id: Id::new(5),
mod_id: Id::new(19),
};
let bytes = modio.download(action).await?.bytes().await?;
sourcepub fn stream(self) -> impl Stream<Item = Result<Bytes>>
pub fn stream(self) -> impl Stream<Item = Result<Bytes>>
Stream
of bytes of the mod file.
§Example
use futures_util::TryStreamExt;
let action = modio::DownloadAction::Primary {
game_id: Id::new(5),
mod_id: Id::new(19),
};
let mut st = Box::pin(modio.download(action).await?.stream());
while let Some(bytes) = st.try_next().await? {
println!("Bytes: {:?}", bytes);
}
sourcepub fn content_length(&self) -> Option<u64>
pub fn content_length(&self) -> Option<u64>
Get the content length from the mod file response.
§Example
let action = modio::DownloadAction::Primary {
game_id: Id::new(5),
mod_id: Id::new(19),
};
let content_length = modio
.download(action)
.await?
.content_length()
.expect("mod file response should have content length");
Auto Trait Implementations§
impl Freeze for Downloader
impl !RefUnwindSafe for Downloader
impl Send for Downloader
impl Sync for Downloader
impl Unpin for Downloader
impl !UnwindSafe for Downloader
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more