pub struct Download { /* private fields */ }Expand description
An active object download returned by Bucket::download once the storage
provider responds.
Object metadata — revision,
size, content_type, and
last_modified — is available immediately. Read
the body all at once with Download::bytes, as a stream of chunks with
Download::bytes_stream, or as an AsyncRead with
Download::into_async_read.
// In one piece.
let bytes = UPLOADS.download("a.pdf").await?.bytes().await?;
// Or as it arrives, straight into a file.
let mut reader = UPLOADS.download("big.bin").await?.into_async_read();
tokio::io::copy(&mut reader, &mut file).await?;Download::revision identifies the exact revision being read, so you can
perform an optimistic read-modify-write:
async fn step() -> Result<bool, objects::Error> {
let read = STATE.download("head").await?;
let revision = read.revision();
let next = advance(&read.bytes().await?);
match STATE.upload_if_match("head", next, revision).await {
Ok(_) => Ok(true),
Err(objects::Error::PreconditionFailed) => Ok(false),
Err(err) => Err(err),
}
}A download holds its underlying connection until it is read to completion or dropped (which cancels the remaining transfer).
Implementations§
Source§impl Download
impl Download
Sourcepub fn of(attrs: &ObjectAttrs, data: impl Into<Bytes>) -> Self
pub fn of(attrs: &ObjectAttrs, data: impl Into<Bytes>) -> Self
Constructs an in-memory Download from attrs and data, useful
when implementing a fake Downloader in tests.
Sourcepub fn revision(&self) -> Revision
pub fn revision(&self) -> Revision
Returns the revision of the downloaded object, matching
ObjectAttrs::revision. Pass this to
upload_if_match,
remove_if_match, or if_match.
Sourcepub fn size(&self) -> u64
pub fn size(&self) -> u64
Returns the total size of the object in bytes, even when downloading a byte range.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Returns the object’s content type, if set.
Sourcepub fn last_modified(&self) -> Option<SystemTime>
pub fn last_modified(&self) -> Option<SystemTime>
Returns when the object was last modified, or None if the provider did
not report it.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Download
impl !Sync for Download
impl !UnwindSafe for Download
impl Forget for Download
impl Freeze for Download
impl Move for Download
impl Send for Download
impl Unpin for Download
impl UnsafeUnpin for Downloadwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const dyn Stream<Item = Result<Bytes, Error>> + Send is !null: UnsafeUnpin,
PhantomData<dyn Stream<Item = Result<Bytes, Error>> + Send>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request