pub struct Download { /* private fields */ }Expand description
A download of an object, begun: returned by Bucket::download, once
the provider has answered. It knows what the provider said of the object
— its revision, size,
content_type and
last_modified — and its contents are still
to come: take them all at once with Download::bytes, as they arrive
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?;The revision is of the very bytes read, which is what replacing an object only if nobody else has since takes:
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 not read to its end holds its connection until it is dropped, which cancels what is left of it.
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
A download of data, as the contents of an object with attrs: what
a fake of Downloader answers with.
Sourcepub fn revision(&self) -> Revision
pub fn revision(&self) -> Revision
The revision the contents are of, for
upload_if_match,
remove_if_match or an if_match: the
same as ObjectAttrs::revision gives for it.
Sourcepub fn size(&self) -> u64
pub fn size(&self) -> u64
The size of the whole object in bytes, also when only a range of it is downloaded.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
The object’s content type, if it has one.
Sourcepub fn last_modified(&self) -> Option<SystemTime>
pub fn last_modified(&self) -> Option<SystemTime>
When the object last changed; None if the provider didn’t say.
Sourcepub fn bytes_stream(
self,
) -> impl Stream<Item = Result<Bytes, Error>> + Send + Unpin + 'static
pub fn bytes_stream( self, ) -> impl Stream<Item = Result<Bytes, Error>> + Send + Unpin + 'static
The contents as they arrive: a stream of chunks, each as large as it happened to arrive.
Sourcepub fn into_async_read(self) -> impl AsyncRead + Unpin + Send + 'static
pub fn into_async_read(self) -> impl AsyncRead + Unpin + Send + 'static
The contents as a reader, for what takes one: a parser, a
decompressor, tokio::io::copy.
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 Download
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