2
2
// so any file larger than 4GB, or an untrusted file with bad data may crash.
3
3
#![ allow( clippy:: cast_possible_truncation) ]
4
4
5
- #[ cfg( feature = "mmap-async-tokio" ) ]
6
- use std:: path:: Path ;
7
-
8
5
use async_recursion:: async_recursion;
9
6
use async_trait:: async_trait;
10
7
use bytes:: Bytes ;
11
- #[ cfg( feature = "http-async" ) ]
12
- use reqwest:: { Client , IntoUrl } ;
13
- #[ cfg( any(
14
- feature = "http-async" ,
15
- feature = "mmap-async-tokio" ,
16
- feature = "s3-async-rustls" ,
17
- feature = "s3-async-native"
18
- ) ) ]
8
+ #[ cfg( feature = "__async" ) ]
19
9
use tokio:: io:: AsyncReadExt ;
20
10
21
- #[ cfg( feature = "http-async" ) ]
22
- use crate :: backend:: HttpBackend ;
23
- #[ cfg( feature = "mmap-async-tokio" ) ]
24
- use crate :: backend:: MmapBackend ;
25
- #[ cfg( any( feature = "s3-async-rustls" , feature = "s3-async-native" ) ) ]
26
- use crate :: backend:: S3Backend ;
27
11
use crate :: cache:: DirCacheResult ;
28
- #[ cfg( any(
29
- feature = "http-async" ,
30
- feature = "mmap-async-tokio" ,
31
- feature = "s3-async-native" ,
32
- feature = "s3-async-rustls"
33
- ) ) ]
12
+ #[ cfg( feature = "__async" ) ]
34
13
use crate :: cache:: { DirectoryCache , NoCache } ;
35
14
use crate :: directory:: { DirEntry , Directory } ;
36
15
use crate :: error:: { PmtError , PmtResult } ;
@@ -227,80 +206,6 @@ impl<B: AsyncBackend + Sync + Send, C: DirectoryCache + Sync + Send> AsyncPmTile
227
206
}
228
207
}
229
208
230
- #[ cfg( feature = "http-async" ) ]
231
- impl AsyncPmTilesReader < HttpBackend , NoCache > {
232
- /// Creates a new `PMTiles` reader from a URL using the Reqwest backend.
233
- ///
234
- /// Fails if [url] does not exist or is an invalid archive. (Note: HTTP requests are made to validate it.)
235
- pub async fn new_with_url < U : IntoUrl > ( client : Client , url : U ) -> PmtResult < Self > {
236
- Self :: new_with_cached_url ( NoCache , client, url) . await
237
- }
238
- }
239
-
240
- #[ cfg( feature = "http-async" ) ]
241
- impl < C : DirectoryCache + Sync + Send > AsyncPmTilesReader < HttpBackend , C > {
242
- /// Creates a new `PMTiles` reader with cache from a URL using the Reqwest backend.
243
- ///
244
- /// Fails if [url] does not exist or is an invalid archive. (Note: HTTP requests are made to validate it.)
245
- pub async fn new_with_cached_url < U : IntoUrl > (
246
- cache : C ,
247
- client : Client ,
248
- url : U ,
249
- ) -> PmtResult < Self > {
250
- let backend = HttpBackend :: try_from ( client, url) ?;
251
-
252
- Self :: try_from_cached_source ( backend, cache) . await
253
- }
254
- }
255
-
256
- #[ cfg( feature = "mmap-async-tokio" ) ]
257
- impl AsyncPmTilesReader < MmapBackend , NoCache > {
258
- /// Creates a new `PMTiles` reader from a file path using the async mmap backend.
259
- ///
260
- /// Fails if [p] does not exist or is an invalid archive.
261
- pub async fn new_with_path < P : AsRef < Path > > ( path : P ) -> PmtResult < Self > {
262
- Self :: new_with_cached_path ( NoCache , path) . await
263
- }
264
- }
265
-
266
- #[ cfg( feature = "mmap-async-tokio" ) ]
267
- impl < C : DirectoryCache + Sync + Send > AsyncPmTilesReader < MmapBackend , C > {
268
- /// Creates a new cached `PMTiles` reader from a file path using the async mmap backend.
269
- ///
270
- /// Fails if [p] does not exist or is an invalid archive.
271
- pub async fn new_with_cached_path < P : AsRef < Path > > ( cache : C , path : P ) -> PmtResult < Self > {
272
- let backend = MmapBackend :: try_from ( path) . await ?;
273
-
274
- Self :: try_from_cached_source ( backend, cache) . await
275
- }
276
- }
277
-
278
- #[ cfg( any( feature = "s3-async-native" , feature = "s3-async-rustls" ) ) ]
279
- impl AsyncPmTilesReader < S3Backend , NoCache > {
280
- /// Creates a new `PMTiles` reader from a URL using the Reqwest backend.
281
- ///
282
- /// Fails if [url] does not exist or is an invalid archive. (Note: HTTP requests are made to validate it.)
283
- pub async fn new_with_bucket_path ( bucket : s3:: Bucket , path : String ) -> PmtResult < Self > {
284
- Self :: new_with_cached_bucket_path ( NoCache , bucket, path) . await
285
- }
286
- }
287
-
288
- #[ cfg( any( feature = "s3-async-native" , feature = "s3-async-rustls" ) ) ]
289
- impl < C : DirectoryCache + Sync + Send > AsyncPmTilesReader < S3Backend , C > {
290
- /// Creates a new `PMTiles` reader with cache from a URL using the Reqwest backend.
291
- ///
292
- /// Fails if [url] does not exist or is an invalid archive. (Note: HTTP requests are made to validate it.)
293
- pub async fn new_with_cached_bucket_path (
294
- cache : C ,
295
- bucket : s3:: Bucket ,
296
- path : String ,
297
- ) -> PmtResult < Self > {
298
- let backend = S3Backend :: from ( bucket, path) ;
299
-
300
- Self :: try_from_cached_source ( backend, cache) . await
301
- }
302
- }
303
-
304
209
#[ async_trait]
305
210
pub trait AsyncBackend {
306
211
/// Reads exactly `length` bytes starting at `offset`
@@ -314,8 +219,8 @@ pub trait AsyncBackend {
314
219
#[ cfg( feature = "mmap-async-tokio" ) ]
315
220
mod tests {
316
221
use super :: AsyncPmTilesReader ;
317
- use crate :: backend:: MmapBackend ;
318
222
use crate :: tests:: { RASTER_FILE , VECTOR_FILE } ;
223
+ use crate :: MmapBackend ;
319
224
320
225
#[ tokio:: test]
321
226
async fn open_sanity_check ( ) {
0 commit comments