@@ -96,20 +96,25 @@ pub trait MapEntry: std::fmt::Debug + Clone + Send + Sync + 'static {
96
96
/// A future that resolves to a reader that can be used to read the data
97
97
fn data_reader ( & self ) -> impl Future < Output = io:: Result < impl AsyncSliceReader > > + Send ;
98
98
99
- /// Encodes data and outboard into a stream which can be imported with [`Store::import_verifiable_stream`].
99
+ /// Encodes data and outboard into a [`AsyncStreamWriter`].
100
+ ///
101
+ /// Data and outboard parts will be interleaved.
102
+ ///
103
+ /// `offset` is the byte offset in the blob to start the stream from. It will be rounded down to
104
+ /// the next chunk group.
100
105
///
101
106
/// Returns immediately without error if `start` is equal or larger than the entry's size.
102
107
fn write_verifiable_stream < ' a > (
103
108
& ' a self ,
104
- start : u64 ,
109
+ offset : u64 ,
105
110
writer : impl AsyncStreamWriter + ' a ,
106
111
) -> impl Future < Output = io:: Result < ( ) > > + ' a {
107
112
async move {
108
113
let size = self . size ( ) . value ( ) ;
109
- if start >= size {
114
+ if offset >= size {
110
115
return Ok ( ( ) ) ;
111
116
}
112
- let ranges = range_from_offset_and_length ( start , size - start ) ;
117
+ let ranges = range_from_offset_and_length ( offset , size - offset ) ;
113
118
let ( outboard, data) = tokio:: try_join!( self . outboard( ) , self . data_reader( ) ) ?;
114
119
encode_ranges_validated ( data, outboard, & ranges, writer) . await ?;
115
120
Ok ( ( ) )
@@ -367,15 +372,19 @@ pub trait Store: ReadableStore + MapMut + std::fmt::Debug {
367
372
}
368
373
369
374
/// Import a blob from a verified stream, as emitted by [`MapEntry::write_verifiable_stream`];
375
+ ///
376
+ /// `total_size` is the total size of the blob as reported by the remote.
377
+ /// `offset` is the byte offset in the blob where the stream starts. It will be rounded
378
+ /// to the next chunk group.
370
379
fn import_verifiable_stream < ' a > (
371
380
& ' a self ,
372
381
hash : Hash ,
373
382
total_size : u64 ,
374
- stream_offset : u64 ,
383
+ offset : u64 ,
375
384
reader : impl AsyncStreamReader + ' a ,
376
385
) -> impl Future < Output = io:: Result < ( ) > > + ' a {
377
386
async move {
378
- if stream_offset >= total_size {
387
+ if offset >= total_size {
379
388
return Err ( io:: Error :: new (
380
389
io:: ErrorKind :: InvalidInput ,
381
390
"offset must not be greater than total_size" ,
@@ -384,7 +393,7 @@ pub trait Store: ReadableStore + MapMut + std::fmt::Debug {
384
393
let entry = self . get_or_create ( hash, total_size) . await ?;
385
394
let mut bw = entry. batch_writer ( ) . await ?;
386
395
387
- let ranges = range_from_offset_and_length ( stream_offset , total_size - stream_offset ) ;
396
+ let ranges = range_from_offset_and_length ( offset , total_size - offset ) ;
388
397
let mut decoder = ResponseDecoder :: new (
389
398
hash. into ( ) ,
390
399
ranges,
0 commit comments