pub struct BlobdClient { /* private fields */ }
Implementations§
Source§impl BlobdClient
impl BlobdClient
Sourcepub fn new(endpoint: String, token_secret: [u8; 32]) -> BlobdClient
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).
Sourcepub fn generate_token_query_param(
&self,
action: AuthTokenAction,
expires_in_seconds: u64,
) -> (&'static str, String)
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.
pub fn generate_presigned_url( &self, key: &str, action: AuthTokenAction, expires_in_seconds: u64, ) -> Url
Sourcepub async fn batch_create_objects<DS, Objects>(
&self,
objects: Objects,
transfer_byte_counter: Option<UnboundedSender<usize>>,
) -> Result<BatchCreatedObjects>
pub async fn batch_create_objects<DS, Objects>( &self, objects: Objects, transfer_byte_counter: Option<UnboundedSender<usize>>, ) -> Result<BatchCreatedObjects>
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 intoBatchCreateObjectEntry
. - If it is dynamically built from another thread/async function, use
futures::channel::mpsc::unbounded
; the receiver already implementsStream
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 aBatchCreateObjectEntry
yields anErr
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 adata_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 yieldErr
, return anOk
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 fortransfer_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.
- Filter out
pub async fn create_object(&self, key: &str, size: u64) -> Result<CreatedObject>
pub async fn commit_object( &self, key: &str, creation: CreatedObject, write_receipts: impl IntoIterator<Item = impl Display>, ) -> Result<()>
pub async fn delete_object(&self, key: &str) -> Result<()>
pub async fn inspect_object(&self, key: &str) -> Result<InspectedObject>
pub async fn read_object( &self, key: &str, start: u64, end: Option<u64>, ) -> Result<impl Stream<Item = Result<Bytes>>>
pub async fn write_object( &self, key: &str, creation: CreatedObject, offset: u64, data: impl Into<Body>, ) -> Result<WrittenObjectPart>
Auto Trait Implementations§
impl Freeze for BlobdClient
impl !RefUnwindSafe for BlobdClient
impl Send for BlobdClient
impl Sync for BlobdClient
impl Unpin for BlobdClient
impl !UnwindSafe for BlobdClient
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
Mutably borrows from an owned value. Read more
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>
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 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>
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