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 4
4
//! with a remote store via rpc calls.
5
5
//!
6
6
//! 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`]
8
8
//! from the different store implementations
9
9
//! (e.g. [`MemStore`](crate::store::mem::MemStore)
10
10
//! 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 {
105
105
} )
106
106
}
107
107
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
+ /// ```
108
128
pub fn reader ( & self , hash : impl Into < Hash > ) -> BlobReader {
109
129
self . reader_with_opts ( ReaderOptions { hash : hash. into ( ) } )
110
130
}
111
131
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.
112
136
pub fn reader_with_opts ( & self , options : ReaderOptions ) -> BlobReader {
113
137
BlobReader :: new ( self . clone ( ) , options)
114
138
}
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ use crate::api::{
11
11
proto:: ExportRangesItem ,
12
12
} ;
13
13
14
+ /// A reader for blobs that implements `AsyncRead` and `AsyncSeek`.
14
15
#[ derive( Debug ) ]
15
16
pub struct BlobReader {
16
17
blobs : Blobs ,
@@ -298,7 +299,6 @@ mod tests {
298
299
async fn reader_partial_fs ( ) -> TestResult < ( ) > {
299
300
let testdir = tempfile:: tempdir ( ) ?;
300
301
let store = FsStore :: load ( testdir. path ( ) . to_owned ( ) ) . await ?;
301
- // reader_smoke_raw(store.blobs()).await?;
302
302
reader_partial ( store. blobs ( ) ) . await ?;
303
303
Ok ( ( ) )
304
304
}
@@ -314,7 +314,6 @@ mod tests {
314
314
async fn reader_smoke_fs ( ) -> TestResult < ( ) > {
315
315
let testdir = tempfile:: tempdir ( ) ?;
316
316
let store = FsStore :: load ( testdir. path ( ) . to_owned ( ) ) . await ?;
317
- // reader_smoke_raw(store.blobs()).await?;
318
317
reader_smoke ( store. blobs ( ) ) . await ?;
319
318
Ok ( ( ) )
320
319
}
You can’t perform that action at this time.
0 commit comments