pub struct Blobs { /* private fields */ }Expand description
Blobs API
Implementations§
Source§impl Blobs
impl Blobs
Sourcepub async fn batch(&self) -> Result<Batch<'_>>
pub async fn batch(&self) -> Result<Batch<'_>>
Creates a new batch scope.
A batch holds open a set of temporary tags that protect blobs from garbage collection for as long as the batch is alive. When the batch is dropped, all its temporary tags are released and the protected blobs become eligible for collection again.
Use a batch whenever a long-running operation needs to protect a blob in the middle of a write, e.g. when downloading a large blob that takes longer than the GC interval. Without a temp tag, GC may collect the partially written data file before the operation completes.
See Batch::temp_tag to pin a specific hash inside the batch scope.
Sourcepub fn reader(&self, hash: impl Into<Hash>) -> BlobReader
pub fn reader(&self, hash: impl Into<Hash>) -> BlobReader
Create a reader for the given hash. The reader implements [tokio::io::AsyncRead] and [tokio::io::AsyncSeek]
and therefore can be used to read the blob’s content.
Any access to parts of the blob that are not present will result in an error.
Example:
use iroh_blobs::{store::mem::MemStore, api::blobs::Blobs};
use tokio::io::AsyncReadExt;
let store = MemStore::new();
let tag = store.add_slice(b"Hello, world!").await?;
let mut reader = store.reader(tag.hash);
let mut buf = String::new();
reader.read_to_string(&mut buf).await?;
assert_eq!(buf, "Hello, world!");
}Sourcepub fn reader_with_opts(&self, options: ReaderOptions) -> BlobReader
pub fn reader_with_opts(&self, options: ReaderOptions) -> BlobReader
Create a reader for the given options. The reader implements [tokio::io::AsyncRead] and [tokio::io::AsyncSeek]
and therefore can be used to read the blob’s content.
Any access to parts of the blob that are not present will result in an error.
pub fn add_slice(&self, data: impl AsRef<[u8]>) -> AddProgress<'_>
pub fn add_bytes(&self, data: impl Into<Bytes>) -> AddProgress<'_>
pub fn add_bytes_with_opts( &self, options: impl Into<AddBytesOptions>, ) -> AddProgress<'_>
pub fn add_path_with_opts( &self, options: impl Into<AddPathOptions>, ) -> AddProgress<'_>
pub fn add_path(&self, path: impl AsRef<Path>) -> AddProgress<'_>
pub async fn add_stream( &self, data: impl Stream<Item = Result<Bytes>> + Send + Sync + 'static, ) -> AddProgress<'_>
pub fn export_ranges( &self, hash: impl Into<Hash>, ranges: impl Into<RangeSet2<u64>>, ) -> ExportRangesProgress
pub fn export_ranges_with_opts( &self, options: ExportRangesOptions, ) -> ExportRangesProgress
pub fn export_bao_with_opts( &self, options: ExportBaoOptions, local_update_cap: usize, ) -> ExportBaoProgress
pub fn export_bao( &self, hash: impl Into<Hash>, ranges: impl Into<ChunkRanges>, ) -> ExportBaoProgress
Sourcepub async fn export_chunk(
&self,
hash: impl Into<Hash>,
offset: u64,
) -> ExportBaoResult<Leaf>
pub async fn export_chunk( &self, hash: impl Into<Hash>, offset: u64, ) -> ExportBaoResult<Leaf>
Export a single chunk from the given hash, at the given offset.
Sourcepub async fn get_bytes(&self, hash: impl Into<Hash>) -> ExportBaoResult<Bytes>
pub async fn get_bytes(&self, hash: impl Into<Hash>) -> ExportBaoResult<Bytes>
Get the entire blob into a Bytes
This will run out of memory when called for very large blobs, so be careful!
Sourcepub fn observe(&self, hash: impl Into<Hash>) -> ObserveProgress
pub fn observe(&self, hash: impl Into<Hash>) -> ObserveProgress
Observe the bitfield of the given hash.
pub fn observe_with_opts(&self, options: ObserveOptions) -> ObserveProgress
pub fn export_with_opts(&self, options: ExportOptions) -> ExportProgress
pub fn export( &self, hash: impl Into<Hash>, target: impl AsRef<Path>, ) -> ExportProgress
pub fn list(&self) -> BlobsListProgress
pub async fn status(&self, hash: impl Into<Hash>) -> Result<BlobStatus>
pub async fn has(&self, hash: impl Into<Hash>) -> Result<bool>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Blobs
impl !RefUnwindSafe for Blobs
impl Send for Blobs
impl Sync for Blobs
impl Unpin for Blobs
impl UnsafeUnpin for Blobs
impl !UnwindSafe for Blobs
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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