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"]
3333object_store = [" dep:object_store" ]
3434
3535[package .metadata .cargo-all-features ]
36-
3736# If your crate has a large number of optional dependencies, skip them for speed
38- skip_optional_dependencies = true
37+ # skip_optional_dependencies = true
3938
4039# Exclude certain features from the build matrix
4140denylist = [" default" ]
Original file line number Diff line number Diff line change 11//! Abstractions for network reading.
22
33use std:: fmt:: Debug ;
4- use std:: io:: Read ;
4+ use std:: io:: { Read , Seek } ;
55use std:: ops:: Range ;
66use std:: sync:: Arc ;
77
88use byteorder:: { BigEndian , LittleEndian , ReadBytesExt } ;
99use bytes:: buf:: Reader ;
1010use 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 ;
1214#[ cfg( feature = "object_store" ) ]
1315use object_store:: ObjectStore ;
1416
@@ -68,6 +70,21 @@ impl AsyncFileReader for Box<dyn AsyncFileReader + '_> {
6870 }
6971}
7072
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+
7188// #[cfg(feature = "tokio")]
7289// impl<T: tokio::io::AsyncRead + tokio::io::AsyncSeek + Unpin + Debug + Send + Sync> AsyncFileReader
7390// 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" ) ]
42use async_tiff:: reader:: ObjectReader ;
53use async_tiff:: TIFF ;
4+ #[ cfg( feature = "object_store" ) ]
65use object_store:: local:: LocalFileSystem ;
6+ #[ cfg( feature = "object_store" ) ]
7+ use std:: env:: current_dir;
8+ use std:: sync:: Arc ;
79
810const TEST_IMAGE_DIR : & str = "tests/image_tiff/images/" ;
911
12+ #[ cfg( feature = "object_store" ) ]
1013pub ( crate ) async fn open_tiff ( filename : & str ) -> TIFF {
1114 let store = Arc :: new ( LocalFileSystem :: new_with_prefix ( current_dir ( ) . unwrap ( ) ) . unwrap ( ) ) ;
1215 let path = format ! ( "{TEST_IMAGE_DIR}/{filename}" ) ;
1316 let reader = Arc :: new ( ObjectReader :: new ( store. clone ( ) , path. as_str ( ) . into ( ) ) ) ;
1417 TIFF :: try_open ( reader) . await . unwrap ( )
1518}
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