File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ num_enum = "0.7.3"
18
18
# Match the version used by pyo3-object-store
19
19
# We'll upgrade to object_store 0.12 ASAP when it comes out
20
20
object_store = { git = " https://github.com/apache/arrow-rs" , rev = " 7a15e4b47ca97df2edef689c9f2ebd2f3888b79e" }
21
+ reqwest = " 0.12"
21
22
thiserror = " 1"
22
23
tokio = { version = " 1.43.0" , optional = true }
23
24
weezl = " 0.1.0"
Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ pub enum AsyncTiffError {
30
30
/// An error during TIFF tag parsing.
31
31
#[ error( transparent) ]
32
32
InternalTIFFError ( #[ from] crate :: tiff:: TiffError ) ,
33
+
34
+ /// Reqwest error
35
+ #[ error( transparent) ]
36
+ ReqwestError ( #[ from] reqwest:: Error ) ,
33
37
}
34
38
35
39
/// Crate-specific result type.
Original file line number Diff line number Diff line change @@ -133,6 +133,35 @@ impl AsyncFileReader for ObjectReader {
133
133
}
134
134
}
135
135
136
+ /// An AsyncFileReader that reads from a URL using reqwest.
137
+ #[ derive( Debug , Clone ) ]
138
+ pub struct ReqwestReader {
139
+ client : reqwest:: Client ,
140
+ url : reqwest:: Url ,
141
+ }
142
+
143
+ impl ReqwestReader {
144
+ /// Construct a new ReqwestReader from a reqwest client and URL.
145
+ pub fn new ( client : reqwest:: Client , url : reqwest:: Url ) -> Self {
146
+ Self { client, url }
147
+ }
148
+ }
149
+
150
+ impl AsyncFileReader for ReqwestReader {
151
+ fn get_bytes ( & self , range : Range < u64 > ) -> BoxFuture < ' _ , AsyncTiffResult < Bytes > > {
152
+ let url = self . url . clone ( ) ;
153
+ let client = self . client . clone ( ) ;
154
+ // HTTP range is inclusive, so we need to subtract 1 from the end
155
+ let range = format ! ( "bytes={}-{}" , range. start, range. end - 1 ) ;
156
+ async move {
157
+ let response = client. get ( url) . header ( "Range" , range) . send ( ) . await ?;
158
+ let bytes = response. bytes ( ) . await ?;
159
+ Ok ( bytes)
160
+ }
161
+ . boxed ( )
162
+ }
163
+ }
164
+
136
165
/// An AsyncFileReader that caches the first `prefetch` bytes of a file.
137
166
#[ derive( Debug ) ]
138
167
pub struct PrefetchReader {
You can’t perform that action at this time.
0 commit comments