Struct BlobdClient

Source
pub struct BlobdClient { /* private fields */ }

Implementations§

Source§

impl BlobdClient

Source

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

The endpoint should be something like https://127.0.0.1:8080 or https://my.blobd.io. Make sure to omit the trailing slash (i.e. empty path).

Source

pub fn generate_token_query_param( &self, action: AuthTokenAction, expires_in_seconds: u64, ) -> (&'static str, String)

NOTE: This does not encode the parameter value, as it’s expected this would be passed into a URL builder. However, currently the token doesn’t contain any character that would require encoding anyway, so it’s safe either way.

Source

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

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, write_receipts: impl IntoIterator<Item = impl Display>, ) -> 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<WrittenObjectPart>

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.

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 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,