pub struct R2ObjectStore { /* private fields */ }Expand description
R2-backed ObjectStore.
Construct with R2ObjectStore::new when keys are already in hand,
or R2ObjectStore::from_vault to pull them from the yah keystore
(with env-var fallback).
Implementations§
Source§impl R2ObjectStore
impl R2ObjectStore
Sourcepub fn new(
account_id: impl Into<String>,
bucket: impl Into<String>,
access_key: impl Into<String>,
secret_key: impl Into<String>,
) -> Result<Self, Error>
pub fn new( account_id: impl Into<String>, bucket: impl Into<String>, access_key: impl Into<String>, secret_key: impl Into<String>, ) -> Result<Self, Error>
Construct with explicit keys.
account_id is the Cloudflare account id (the subdomain in
<account_id>.r2.cloudflarestorage.com).
Sourcepub fn from_vault(
account_id: impl Into<String>,
bucket: impl Into<String>,
) -> Result<Self, Error>
pub fn from_vault( account_id: impl Into<String>, bucket: impl Into<String>, ) -> Result<Self, Error>
Construct from the yah keystore (vault), falling back to env vars.
Reads cloudflare-r2-access-key-id / cloudflare-r2-secret-key slots
(env fallback CF_R2_ACCESS_KEY_ID / CF_R2_SECRET_KEY). Returns
Error::Auth if either is missing.
Source§impl R2ObjectStore
impl R2ObjectStore
Sourcepub fn list_prefix_detailed(
&self,
prefix: &str,
) -> Result<Vec<ObjectMeta>, Error>
pub fn list_prefix_detailed( &self, prefix: &str, ) -> Result<Vec<ObjectMeta>, Error>
List objects under prefix returning key + size + last-modified.
Same paginated request as ObjectStore::list_prefix but parses the
<Size> and <LastModified> siblings of each <Key> element. Used by
the data-tab bucket viewer to render a directory-style listing.
Trait Implementations§
Source§impl ObjectStore for R2ObjectStore
impl ObjectStore for R2ObjectStore
Source§fn put(&self, key: &str, data: Vec<u8>) -> Result<(), Error>
fn put(&self, key: &str, data: Vec<u8>) -> Result<(), Error>
data at key. Overwrites any existing object unconditionally.Source§fn get(&self, key: &str) -> Result<Option<Vec<u8>>, Error>
fn get(&self, key: &str) -> Result<Option<Vec<u8>>, Error>
key. Returns None when the key does not exist —
NotFound is reserved for ambiguous cases (HEAD-then-GET race etc.).Source§fn head(&self, key: &str) -> Result<bool, Error>
fn head(&self, key: &str) -> Result<bool, Error>
key exists. Cheaper than get for backends that
support HEAD; the default impl falls back to get(...).is_some().Source§fn delete(&self, key: &str) -> Result<(), Error>
fn delete(&self, key: &str) -> Result<(), Error>
key. Idempotent — succeeds whether or not the key existed.