@@ -27,10 +27,10 @@ use crate::error::{AiocogeoError, Result};
2727/// [`tokio::fs::File`]: https://docs.rs/tokio/latest/tokio/fs/struct.File.html
2828pub trait AsyncFileReader : Send {
2929 /// 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 > > ;
3131
3232 /// 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 > > > {
3434 async move {
3535 let mut result = Vec :: with_capacity ( ranges. len ( ) ) ;
3636
@@ -47,24 +47,24 @@ pub trait AsyncFileReader: Send {
4747
4848/// This allows Box<dyn AsyncFileReader + '_> to be used as an AsyncFileReader,
4949impl 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 > > {
5151 self . as_mut ( ) . get_bytes ( range)
5252 }
5353
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 > > > {
5555 self . as_mut ( ) . get_byte_ranges ( ranges)
5656 }
5757}
5858
5959#[ cfg( feature = "tokio" ) ]
6060impl < 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 > > {
6262 use tokio:: io:: { AsyncReadExt , AsyncSeekExt } ;
6363
6464 async move {
65- self . seek ( SeekFrom :: Start ( range. start as u64 ) ) . await ?;
65+ self . seek ( SeekFrom :: Start ( range. start ) ) . await ?;
6666
67- let to_read = range. end - range. start ;
67+ let to_read = ( range. end - range. start ) . try_into ( ) . unwrap ( ) ;
6868 let mut buffer = Vec :: with_capacity ( to_read) ;
6969 let read = self . take ( to_read as u64 ) . read_to_end ( & mut buffer) . await ?;
7070 if read != to_read {
@@ -93,14 +93,14 @@ impl ObjectReader {
9393}
9494
9595impl 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 > > {
9797 self . store
9898 . get_range ( & self . path , range)
9999 . map_err ( |e| e. into ( ) )
100100 . boxed ( )
101101 }
102102
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 > > >
104104 where
105105 Self : Send ,
106106 {
@@ -160,7 +160,7 @@ impl AsyncCursor {
160160 }
161161
162162 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 _ ;
164164 self . offset += length;
165165 self . reader . get_bytes ( range) . await . unwrap ( )
166166 }
0 commit comments