pub struct MemStore { /* private fields */ }
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>§
pub async fn batch(&self) -> Result<Batch<'_>>
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.