pub struct FsStore { /* private fields */ }Expand description
A file based store.
A store can be created using load or load_with_opts.
Load will use the default options and create the required directories, while load_with_opts allows
you to customize the options and the location of the database. Both variants will create the database
if it does not exist, and load an existing database if one is found at the configured location.
In addition to implementing the Store API via Deref,
there are a few additional methods that are specific to file based stores, such as dump.
Implementations§
Methods from Deref<Target = Store>§
The tags API.
Sourcepub fn downloader(&self, endpoint: &Endpoint) -> Downloader
pub fn downloader(&self, endpoint: &Endpoint) -> Downloader
Create a downloader for more complex downloads.
Unlike the other APIs, this creates an object that has internal state, so don’t create it ad hoc but store it somewhere if you need it multiple times.
pub async fn sync_db(&self) -> RequestResult<()>
pub async fn shutdown(&self) -> Result<()>
Sourcepub async fn wait_idle(&self) -> Result<()>
pub async fn wait_idle(&self) -> Result<()>
Waits for the store to become completely idle.
This is mostly useful for tests, where you want to check that e.g. the store has written all data to disk.
Note that a store is not guaranteed to become idle, if it is being interacted with concurrently. So this might wait forever.
Also note that once you get the callback, the store is not guaranteed to still be idle. All this tells you that there was a point in time where the store was idle between the call and the response.
Methods from Deref<Target = 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 FsStore
impl !RefUnwindSafe for FsStore
impl Send for FsStore
impl Sync for FsStore
impl Unpin for FsStore
impl UnsafeUnpin for FsStore
impl !UnwindSafe for FsStore
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