@@ -27,10 +27,10 @@ use crate::error::{AiocogeoError, Result};
27
27
/// [`tokio::fs::File`]: https://docs.rs/tokio/latest/tokio/fs/struct.File.html
28
28
pub trait AsyncFileReader : Send {
29
29
/// Retrieve the bytes in `range`
30
- fn get_bytes ( & mut self , range : Range < usize > ) -> BoxFuture < ' _ , Result < Bytes > > ;
30
+ fn get_bytes ( & mut self , range : Range < u64 > ) -> BoxFuture < ' _ , Result < Bytes > > ;
31
31
32
32
/// Retrieve multiple byte ranges. The default implementation will call `get_bytes` sequentially
33
- fn get_byte_ranges ( & mut self , ranges : Vec < Range < usize > > ) -> BoxFuture < ' _ , Result < Vec < Bytes > > > {
33
+ fn get_byte_ranges ( & mut self , ranges : Vec < Range < u64 > > ) -> BoxFuture < ' _ , Result < Vec < Bytes > > > {
34
34
async move {
35
35
let mut result = Vec :: with_capacity ( ranges. len ( ) ) ;
36
36
@@ -47,24 +47,24 @@ pub trait AsyncFileReader: Send {
47
47
48
48
/// This allows Box<dyn AsyncFileReader + '_> to be used as an AsyncFileReader,
49
49
impl AsyncFileReader for Box < dyn AsyncFileReader + ' _ > {
50
- fn get_bytes ( & mut self , range : Range < usize > ) -> BoxFuture < ' _ , Result < Bytes > > {
50
+ fn get_bytes ( & mut self , range : Range < u64 > ) -> BoxFuture < ' _ , Result < Bytes > > {
51
51
self . as_mut ( ) . get_bytes ( range)
52
52
}
53
53
54
- fn get_byte_ranges ( & mut self , ranges : Vec < Range < usize > > ) -> BoxFuture < ' _ , Result < Vec < Bytes > > > {
54
+ fn get_byte_ranges ( & mut self , ranges : Vec < Range < u64 > > ) -> BoxFuture < ' _ , Result < Vec < Bytes > > > {
55
55
self . as_mut ( ) . get_byte_ranges ( ranges)
56
56
}
57
57
}
58
58
59
59
#[ cfg( feature = "tokio" ) ]
60
60
impl < T : tokio:: io:: AsyncRead + tokio:: io:: AsyncSeek + Unpin + Send > AsyncFileReader for T {
61
- fn get_bytes ( & mut self , range : Range < usize > ) -> BoxFuture < ' _ , Result < Bytes > > {
61
+ fn get_bytes ( & mut self , range : Range < u64 > ) -> BoxFuture < ' _ , Result < Bytes > > {
62
62
use tokio:: io:: { AsyncReadExt , AsyncSeekExt } ;
63
63
64
64
async move {
65
- self . seek ( SeekFrom :: Start ( range. start as u64 ) ) . await ?;
65
+ self . seek ( SeekFrom :: Start ( range. start ) ) . await ?;
66
66
67
- let to_read = range. end - range. start ;
67
+ let to_read = ( range. end - range. start ) . try_into ( ) . unwrap ( ) ;
68
68
let mut buffer = Vec :: with_capacity ( to_read) ;
69
69
let read = self . take ( to_read as u64 ) . read_to_end ( & mut buffer) . await ?;
70
70
if read != to_read {
@@ -93,14 +93,14 @@ impl ObjectReader {
93
93
}
94
94
95
95
impl AsyncFileReader for ObjectReader {
96
- fn get_bytes ( & mut self , range : Range < usize > ) -> BoxFuture < ' _ , Result < Bytes > > {
96
+ fn get_bytes ( & mut self , range : Range < u64 > ) -> BoxFuture < ' _ , Result < Bytes > > {
97
97
self . store
98
98
. get_range ( & self . path , range)
99
99
. map_err ( |e| e. into ( ) )
100
100
. boxed ( )
101
101
}
102
102
103
- fn get_byte_ranges ( & mut self , ranges : Vec < Range < usize > > ) -> BoxFuture < ' _ , Result < Vec < Bytes > > >
103
+ fn get_byte_ranges ( & mut self , ranges : Vec < Range < u64 > > ) -> BoxFuture < ' _ , Result < Vec < Bytes > > >
104
104
where
105
105
Self : Send ,
106
106
{
@@ -160,7 +160,7 @@ impl AsyncCursor {
160
160
}
161
161
162
162
pub ( crate ) async fn read ( & mut self , length : usize ) -> Bytes {
163
- let range = self . offset .. self . offset + length;
163
+ let range = self . offset as _ .. ( self . offset + length) as _ ;
164
164
self . offset += length;
165
165
self . reader . get_bytes ( range) . await . unwrap ( )
166
166
}
0 commit comments