File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 44//! with a remote store via rpc calls.
55//!
66//! The entry point for the api is the [`Store`] struct. There are several ways
7- //! to obtain a `Store` instance: it is available via [`Deref`](std::ops::Deref)
7+ //! to obtain a `Store` instance: it is available via [`Deref`]
88//! from the different store implementations
99//! (e.g. [`MemStore`](crate::store::mem::MemStore)
1010//! and [`FsStore`](crate::store::fs::FsStore)) as well as on the
Original file line number Diff line number Diff line change @@ -105,10 +105,34 @@ impl Blobs {
105105 } )
106106 }
107107
108+ /// Create a reader for the given hash. The reader implements [`tokio::io::AsyncRead`] and [`tokio::io::AsyncSeek`]
109+ /// and therefore can be used to read the blob's content.
110+ ///
111+ /// Any access to parts of the blob that are not present will result in an error.
112+ ///
113+ /// Example:
114+ /// ```rust
115+ /// use iroh_blobs::{store::mem::MemStore, api::blobs::Blobs};
116+ /// use tokio::io::AsyncReadExt;
117+ ///
118+ /// # async fn example() -> anyhow::Result<()> {
119+ /// let store = MemStore::new();
120+ /// let tag = store.add_slice(b"Hello, world!").await?;
121+ /// let mut reader = store.reader(tag.hash);
122+ /// let mut buf = String::new();
123+ /// reader.read_to_string(&mut buf).await?;
124+ /// assert_eq!(buf, "Hello, world!");
125+ /// # Ok(())
126+ /// }
127+ /// ```
108128 pub fn reader ( & self , hash : impl Into < Hash > ) -> BlobReader {
109129 self . reader_with_opts ( ReaderOptions { hash : hash. into ( ) } )
110130 }
111131
132+ /// Create a reader for the given options. The reader implements [`tokio::io::AsyncRead`] and [`tokio::io::AsyncSeek`]
133+ /// and therefore can be used to read the blob's content.
134+ ///
135+ /// Any access to parts of the blob that are not present will result in an error.
112136 pub fn reader_with_opts ( & self , options : ReaderOptions ) -> BlobReader {
113137 BlobReader :: new ( self . clone ( ) , options)
114138 }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ use crate::api::{
1111 proto:: ExportRangesItem ,
1212} ;
1313
14+ /// A reader for blobs that implements `AsyncRead` and `AsyncSeek`.
1415#[ derive( Debug ) ]
1516pub struct BlobReader {
1617 blobs : Blobs ,
@@ -298,7 +299,6 @@ mod tests {
298299 async fn reader_partial_fs ( ) -> TestResult < ( ) > {
299300 let testdir = tempfile:: tempdir ( ) ?;
300301 let store = FsStore :: load ( testdir. path ( ) . to_owned ( ) ) . await ?;
301- // reader_smoke_raw(store.blobs()).await?;
302302 reader_partial ( store. blobs ( ) ) . await ?;
303303 Ok ( ( ) )
304304 }
@@ -314,7 +314,6 @@ mod tests {
314314 async fn reader_smoke_fs ( ) -> TestResult < ( ) > {
315315 let testdir = tempfile:: tempdir ( ) ?;
316316 let store = FsStore :: load ( testdir. path ( ) . to_owned ( ) ) . await ?;
317- // reader_smoke_raw(store.blobs()).await?;
318317 reader_smoke ( store. blobs ( ) ) . await ?;
319318 Ok ( ( ) )
320319 }
You can’t perform that action at this time.
0 commit comments