File tree Expand file tree Collapse file tree 3 files changed +34
-7
lines changed Expand file tree Collapse file tree 3 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -33,9 +33,8 @@ reqwest = ["dep:reqwest"]
33
33
object_store = [" dep:object_store" ]
34
34
35
35
[package .metadata .cargo-all-features ]
36
-
37
36
# If your crate has a large number of optional dependencies, skip them for speed
38
- skip_optional_dependencies = true
37
+ # skip_optional_dependencies = true
39
38
40
39
# Exclude certain features from the build matrix
41
40
denylist = [" default" ]
Original file line number Diff line number Diff line change 1
1
//! Abstractions for network reading.
2
2
3
3
use std:: fmt:: Debug ;
4
- use std:: io:: Read ;
4
+ use std:: io:: { Read , Seek } ;
5
5
use std:: ops:: Range ;
6
6
use std:: sync:: Arc ;
7
7
8
8
use byteorder:: { BigEndian , LittleEndian , ReadBytesExt } ;
9
9
use bytes:: buf:: Reader ;
10
10
use bytes:: { Buf , Bytes } ;
11
- use futures:: future:: { BoxFuture , FutureExt , TryFutureExt } ;
11
+ use futures:: future:: { BoxFuture , FutureExt } ;
12
+ #[ cfg( feature = "object_store" ) ]
13
+ use futures:: TryFutureExt ;
12
14
#[ cfg( feature = "object_store" ) ]
13
15
use object_store:: ObjectStore ;
14
16
@@ -68,6 +70,21 @@ impl AsyncFileReader for Box<dyn AsyncFileReader + '_> {
68
70
}
69
71
}
70
72
73
+ impl AsyncFileReader for std:: fs:: File {
74
+ fn get_bytes ( & self , range : Range < u64 > ) -> BoxFuture < ' _ , AsyncTiffResult < Bytes > > {
75
+ async move {
76
+ let mut file = self . try_clone ( ) ?;
77
+ file. seek ( std:: io:: SeekFrom :: Start ( range. start ) ) ?;
78
+ let len = ( range. end - range. start ) as usize ;
79
+ let mut buf = vec ! [ 0u8 ; len] ;
80
+ file. read_exact ( & mut buf) ?;
81
+ let res = Bytes :: copy_from_slice ( & buf) ;
82
+ Ok ( res)
83
+ }
84
+ . boxed ( )
85
+ }
86
+ }
87
+
71
88
// #[cfg(feature = "tokio")]
72
89
// impl<T: tokio::io::AsyncRead + tokio::io::AsyncSeek + Unpin + Debug + Send + Sync> AsyncFileReader
73
90
// for T
Original file line number Diff line number Diff line change 1
- use std:: env:: current_dir;
2
- use std:: sync:: Arc ;
3
-
1
+ #[ cfg( feature = "object_store" ) ]
4
2
use async_tiff:: reader:: ObjectReader ;
5
3
use async_tiff:: TIFF ;
4
+ #[ cfg( feature = "object_store" ) ]
6
5
use object_store:: local:: LocalFileSystem ;
6
+ #[ cfg( feature = "object_store" ) ]
7
+ use std:: env:: current_dir;
8
+ use std:: sync:: Arc ;
7
9
8
10
const TEST_IMAGE_DIR : & str = "tests/image_tiff/images/" ;
9
11
12
+ #[ cfg( feature = "object_store" ) ]
10
13
pub ( crate ) async fn open_tiff ( filename : & str ) -> TIFF {
11
14
let store = Arc :: new ( LocalFileSystem :: new_with_prefix ( current_dir ( ) . unwrap ( ) ) . unwrap ( ) ) ;
12
15
let path = format ! ( "{TEST_IMAGE_DIR}/{filename}" ) ;
13
16
let reader = Arc :: new ( ObjectReader :: new ( store. clone ( ) , path. as_str ( ) . into ( ) ) ) ;
14
17
TIFF :: try_open ( reader) . await . unwrap ( )
15
18
}
19
+
20
+ #[ cfg( not( feature = "object_store" ) ) ]
21
+ pub ( crate ) async fn open_tiff ( filename : & str ) -> TIFF {
22
+ // let store = Arc::new(LocalFileSystem::new_with_prefix(current_dir().unwrap()).unwrap());
23
+ let path = format ! ( "{TEST_IMAGE_DIR}/{filename}" ) ;
24
+ let reader = Arc :: new ( std:: fs:: File :: open ( path) . expect ( "could not open file" ) ) ;
25
+ TIFF :: try_open ( reader) . await . unwrap ( )
26
+ }
You can’t perform that action at this time.
0 commit comments