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

source

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?;
source

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?;
source

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);
}
source

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§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more