pub struct BlobdClient { /* private fields */ }

Implementations§

source§

impl BlobdClient

source

pub fn new(url_prefix: String, token_secret: [u8; 32]) -> BlobdClient

source

pub fn generate_presigned_url( &self, key: &str, action: AuthTokenAction, expires_in_seconds: u64 ) -> String

source

pub async fn batch_create_objects<DS, Objects>( &self, objects: Objects, transfer_byte_counter: Option<UnboundedSender<usize>> ) -> Result<BatchCreatedObjects>where DS: 'static + Stream<Item = Result<Bytes, Box<dyn Error + Send + Sync>>> + Send + Sync, Objects: 'static + Stream<Item = BatchCreateObjectEntry<DS>> + Send + Sync,

Parts to this method:

  • The list of objects. It’s an infallible stream to allow for scenarios where the list is not known ahead of time or is buffered asynchronously.
  • Each object’s data. It’s a fallable stream of chunks of bytes, using the bytes::Bytes type as that’s what reqwest requires. Approaches to the list of objects:
  • If it’s all in memory, use futures::stream::iter(my_list_of_objects).
  • If it can be derived from an existing stream, use the StreamExt methods to transform items into BatchCreateObjectEntry.
  • If it is dynamically built from another thread/async function, use futures::channel::mpsc::unbounded; the receiver already implements Stream and can be provided as the list. Approaches to object data stream:
  • If it’s all in memory, use futures::stream::once(Ok(bytes::Bytes::from(my_object_data))).
  • If it’s a synchronous Read, wrap in a Stream that reads chunks into a Bytes, preferably on a different thread (e.g. spawn_blocking).
  • If it’s an AsyncRead, read in chunks and wrap each chunk with Bytes::from. Approaches to error handling:
  • The blobd server will never return a bad status, but will bail as soon as an error occurs.
  • However, reqwest will bail if the request body fails, which can occur if a data_stream of a BatchCreateObjectEntry yields an Err chunk.
  • If reqwest bails, the response will be unavailable and the amount of successfully committed objects will not be returned.
  • Therefore, there are some optional approaches worth considering:
    • Filter out BatchCreateObjectEntry items that have a data_stream that will definitely fail, as once an entry starts being transferred, there’s no way to skip over it midway.
    • When a data_stream chunk is about to yield Err, return an Ok instead with empty data and stop the object list stream (as the current data transferred is midway in an object and there’s no way to skip over it). The server will notice that the object was not completely uploaded, decide to bail, and return the successful count. Provide an optional async channel sender for transfer_byte_counter to get data stream chunk sizes as they’re about to be uploaded, which can be useful for calculating transfer progress or rate.
source

pub async fn create_object(&self, key: &str, size: u64) -> Result<CreatedObject>

source

pub async fn commit_object( &self, key: &str, creation: CreatedObject ) -> Result<()>

source

pub async fn delete_object(&self, key: &str) -> Result<()>

source

pub async fn inspect_object(&self, key: &str) -> Result<InspectedObject>

source

pub async fn read_object( &self, key: &str, start: u64, end: Option<u64> ) -> Result<impl Stream<Item = Result<Bytes>>>

source

pub async fn write_object( &self, key: &str, creation: CreatedObject, offset: u64, data: impl Into<Body> ) -> Result<()>

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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 Twhere U: From<T>,

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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