Skip to content

Commit a78f2af

Browse files
committed
fixed errors/warnings for all features: Added std::fs::File AsyncFileReader impl
1 parent b1ea079 commit a78f2af

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ reqwest = ["dep:reqwest"]
3333
object_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
4140
denylist = ["default"]

src/reader.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
//! Abstractions for network reading.
22
33
use std::fmt::Debug;
4-
use std::io::Read;
4+
use std::io::{Read, Seek};
55
use std::ops::Range;
66
use std::sync::Arc;
77

88
use byteorder::{BigEndian, LittleEndian, ReadBytesExt};
99
use bytes::buf::Reader;
1010
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;
1214
#[cfg(feature = "object_store")]
1315
use 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

tests/image_tiff/util.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
use std::env::current_dir;
2-
use std::sync::Arc;
3-
1+
#[cfg(feature = "object_store")]
42
use async_tiff::reader::ObjectReader;
53
use async_tiff::TIFF;
4+
#[cfg(feature = "object_store")]
65
use object_store::local::LocalFileSystem;
6+
#[cfg(feature = "object_store")]
7+
use std::env::current_dir;
8+
use std::sync::Arc;
79

810
const TEST_IMAGE_DIR: &str = "tests/image_tiff/images/";
911

12+
#[cfg(feature = "object_store")]
1013
pub(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+
}

0 commit comments

Comments
 (0)