Struct B2
pub struct B2 { /* private fields */ }services-b2 only.Expand description
b2 services support.
§Capabilities
Depending on its configuration and the backing system, this service can expose:
- create_dir
- stat
- read
- write
- delete
- list
- copy
- restore
- rename
- presign
Inspect the effective capability set with opendal_core::Operator::info and
opendal_core::OperatorInfo::capability after building an operator.
§Verified writes
write_with(path, data).checksum(WriteChecksum::Any) and
writer_with(path).checksum(WriteChecksum::Any) ask B2 to verify SHA-1.
An ordinary upload returns the verified ChecksumAlgo::Sha1 digest in
Metadata::checksum(). A large-file upload verifies each part and returns
None from Metadata::checksum() because B2 only verifies the part digests.
B2 rejects Fast, Algo, Expected, and all presigned writes with an
explicit checksum intent before sending a request. Writes without a checksum
intent use B2’s do_not_verify mode.
B2 digest rejections return ChecksumMismatch. An upload rejected for a
body mismatch can be retried with its buffered data. A rejected part digest
list on completion is a non-temporary error. If B2 accepts an ordinary upload
but the response fails to confirm the digest, the object may already be visible.
§File metadata by version
stat_with(path).version(file_id) returns metadata for a B2 data version of
that file. The application key needs readFiles permission. A version that
has been permanently deleted, belongs to a different path, or is a hide marker
returns NotFound. Ordinary stat and list expose current file IDs through
Metadata::version(). Current and versioned stat and list results also expose
the stored Content-Disposition in Metadata::content_disposition() when B2
supplies its reserved file info field.
§File version listing
list_with(path) and lister_with(path) return current visible files by
default. Set versions(true) to include historical data versions. Set
deleted(true) to include current and historical hide markers. Use both
options to include all data versions and hide markers. The application key
needs listFiles permission.
Data versions and hide markers expose their B2 file IDs in
Metadata::version(). With either option enabled, Metadata::is_current()
indicates whether a data version or hide marker is current for its name. Hide
markers have Metadata::is_deleted() set to true, zero content length, and
the B2 upload timestamp in Metadata::last_modified(). Listings omit unfinished
uploads. Non-recursive listings include virtual directories without version
metadata.
§File reads by version
read_with(path).version(file_id) and reader_with(path).version(file_id)
read a B2 data version of the specified file. The application key needs
readFiles permission. A version belonging to a different path returns
NotFound. The reader checks the version against the configured bucket and
path before each download. Range reads report the selected version’s full length
in the reader’s metadata. Response overrides with a selected version return
Unsupported.
§Presigned downloads
presign_read and presign_stat both return a B2 download request that uses
GET and addresses the file by name. presign_read_options and
presign_stat_options return Unsupported when a version is set. The
option-bearing variants support overriding the response
Content-Type, Content-Disposition, and Cache-Control. Use the returned
method, URL, and headers to execute the request.
§Presigned uploads
presign_write_options returns a single-object POST. It uses content_type
for Content-Type and defaults to b2/x-auto. The cache_control,
content_disposition, content_encoding, and content_language options
use reserved B2 file-info headers.
OpenDAL sends user_metadata as X-Bz-Info-* headers. A dedicated option
takes precedence over entries that map to the same native header, matching
header names case-insensitively. Other entries are preserved, including
content-type metadata in its own X-Bz-Info-Content-Type header.
§Restore
restore(path) removes one current B2 hide marker when a data version still
exists for the path. A live file keeps its current version, and a path with no
remaining data versions returns NotFound. The application key needs listFiles
and deleteFiles permissions to remove the marker.
restore_with(path).version(file_id) copies a data version of the same file to
make it current. Version promotion requires readFiles and writeFiles
and is subject to the B2 Copy File size limit.
§Configuration
Use crate::B2Config for serializable configuration and this builder’s
methods for direct construction. The field and method documentation defines
accepted values, defaults, and environment interaction.
§Example
§Via Builder
use opendal_core::Operator;
use opendal_core::Result;
use opendal_service_b2::B2;
#[tokio::main]
async fn main() -> Result<()> {
// create backend builder
let mut builder = B2::default()
// set the storage bucket for OpenDAL
.root("/")
// set the key_id for OpenDAL
.application_key_id("xxxxxxxxxx")
// set the key_id for OpenDAL
.application_key("xxxxxxxxxx")
// set the bucket name for OpenDAL
.bucket("opendal")
// set the bucket_id for OpenDAL
.bucket_id("xxxxxxxxxxxxx");
let op: Operator = Operator::new(builder)?;
Ok(())
}Implementations§
§impl B2Builder
impl B2Builder
pub fn root(self, root: &str) -> B2Builder
pub fn root(self, root: &str) -> B2Builder
Set root of this backend.
All operations will happen under this root.
pub fn application_key_id(self, application_key_id: &str) -> B2Builder
pub fn application_key_id(self, application_key_id: &str) -> B2Builder
application_key_id of this backend.
pub fn application_key(self, application_key: &str) -> B2Builder
pub fn application_key(self, application_key: &str) -> B2Builder
application_key of this backend.
pub fn bucket(self, bucket: &str) -> B2Builder
pub fn bucket(self, bucket: &str) -> B2Builder
Set bucket name of this backend. You can find it in https://secure.backblaze.com/b2_buckets.html
pub fn bucket_id(self, bucket_id: &str) -> B2Builder
pub fn bucket_id(self, bucket_id: &str) -> B2Builder
Set bucket id of this backend. You can find it in https://secure.backblaze.com/b2_buckets.html
Trait Implementations§
Auto Trait Implementations§
impl Freeze for B2Builder
impl RefUnwindSafe for B2Builder
impl Send for B2Builder
impl Sync for B2Builder
impl Unpin for B2Builder
impl UnsafeUnpin for B2Builder
impl UnwindSafe for B2Builder
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§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§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].impl<T> MaybeSend for Twhere
T: Send,
impl<T> MaybeSend for Twhere
T: Send,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<E> ResultError for E
§impl<T> Scope for T
impl<T> Scope for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.