-
Notifications
You must be signed in to change notification settings - Fork 2
Feature gate object_store
and reqwest
#71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
3b6a51d
8476f2c
1b4de75
11fea2a
b1ea079
a78f2af
a6821e6
fb1c71a
feefadd
9e04ae9
3122f19
3cbd6c6
05c4fe1
356dc8b
93ee7b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ impl TIFF { | |
} | ||
} | ||
|
||
#[cfg(feature = "object_store")] | ||
#[cfg(test)] | ||
mod test { | ||
use std::io::BufReader; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,14 +1,17 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
//! Abstractions for network reading. | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
use std::fmt::Debug; | ||||||||||||||||||||||||||||||||||||||||||||||
use std::io::Read; | ||||||||||||||||||||||||||||||||||||||||||||||
use std::io::{Read, Seek}; | ||||||||||||||||||||||||||||||||||||||||||||||
use std::ops::Range; | ||||||||||||||||||||||||||||||||||||||||||||||
use std::sync::Arc; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
use byteorder::{BigEndian, LittleEndian, ReadBytesExt}; | ||||||||||||||||||||||||||||||||||||||||||||||
use bytes::buf::Reader; | ||||||||||||||||||||||||||||||||||||||||||||||
use bytes::{Buf, Bytes}; | ||||||||||||||||||||||||||||||||||||||||||||||
use futures::future::{BoxFuture, FutureExt, TryFutureExt}; | ||||||||||||||||||||||||||||||||||||||||||||||
use futures::future::{BoxFuture, FutureExt}; | ||||||||||||||||||||||||||||||||||||||||||||||
#[cfg(feature = "object_store")] | ||||||||||||||||||||||||||||||||||||||||||||||
use futures::TryFutureExt; | ||||||||||||||||||||||||||||||||||||||||||||||
#[cfg(feature = "object_store")] | ||||||||||||||||||||||||||||||||||||||||||||||
use object_store::ObjectStore; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
use crate::error::{AsyncTiffError, AsyncTiffResult}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -67,6 +70,21 @@ impl AsyncFileReader for Box<dyn AsyncFileReader + '_> { | |||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
impl AsyncFileReader for std::fs::File { | ||||||||||||||||||||||||||||||||||||||||||||||
fn get_bytes(&self, range: Range<u64>) -> BoxFuture<'_, AsyncTiffResult<Bytes>> { | ||||||||||||||||||||||||||||||||||||||||||||||
async move { | ||||||||||||||||||||||||||||||||||||||||||||||
let mut file = self.try_clone()?; | ||||||||||||||||||||||||||||||||||||||||||||||
file.seek(std::io::SeekFrom::Start(range.start))?; | ||||||||||||||||||||||||||||||||||||||||||||||
let len = (range.end - range.start) as usize; | ||||||||||||||||||||||||||||||||||||||||||||||
let mut buf = vec![0u8; len]; | ||||||||||||||||||||||||||||||||||||||||||||||
file.read_exact(&mut buf)?; | ||||||||||||||||||||||||||||||||||||||||||||||
let res = Bytes::copy_from_slice(&buf); | ||||||||||||||||||||||||||||||||||||||||||||||
Ok(res) | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
.boxed() | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
// #[cfg(feature = "tokio")] | |
// impl<T: tokio::io::AsyncRead + tokio::io::AsyncSeek + Unpin + Debug + Send + Sync> AsyncFileReader | |
// for T | |
// { | |
// fn get_bytes(&self, range: Range<u64>) -> BoxFuture<'_, AsyncTiffResult<Bytes>> { | |
// use tokio::io::{AsyncReadExt, AsyncSeekExt}; | |
// async move { | |
// self.seek(std::io::SeekFrom::Start(range.start)).await?; | |
// let to_read = (range.end - range.start).try_into().unwrap(); | |
// let mut buffer = Vec::with_capacity(to_read); | |
// let read = self.take(to_read as u64).read_to_end(&mut buffer).await?; | |
// if read != to_read { | |
// return Err(AsyncTiffError::EndOfFile(to_read, read)); | |
// } | |
// Ok(buffer.into()) | |
// } | |
// .boxed() | |
// } | |
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem I had was that the feature testing also wants to test with all features disabled, and I didn't exactly know how to deal with that... added a fallback in util.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also tokio's asyncread require &mut self
, so I changed the impl to tokio::fs::File
, where we can try_clone()
on &self
. There doesn't seem to be a TryClone trait
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
use std::env::current_dir; | ||
use std::sync::Arc; | ||
|
||
#[cfg(feature = "object_store")] | ||
use async_tiff::reader::ObjectReader; | ||
use async_tiff::TIFF; | ||
#[cfg(feature = "object_store")] | ||
use object_store::local::LocalFileSystem; | ||
#[cfg(feature = "object_store")] | ||
use std::env::current_dir; | ||
use std::sync::Arc; | ||
|
||
const TEST_IMAGE_DIR: &str = "tests/image_tiff/images/"; | ||
|
||
#[cfg(feature = "object_store")] | ||
pub(crate) async fn open_tiff(filename: &str) -> TIFF { | ||
let store = Arc::new(LocalFileSystem::new_with_prefix(current_dir().unwrap()).unwrap()); | ||
let path = format!("{TEST_IMAGE_DIR}/{filename}"); | ||
let reader = Arc::new(ObjectReader::new(store.clone(), path.as_str().into())); | ||
TIFF::try_open(reader).await.unwrap() | ||
} | ||
|
||
#[cfg(not(feature = "object_store"))] | ||
pub(crate) async fn open_tiff(filename: &str) -> TIFF { | ||
// let store = Arc::new(LocalFileSystem::new_with_prefix(current_dir().unwrap()).unwrap()); | ||
let path = format!("{TEST_IMAGE_DIR}/{filename}"); | ||
let reader = Arc::new(std::fs::File::open(path).expect("could not open file")); | ||
TIFF::try_open(reader).await.unwrap() | ||
} |
Uh oh!
There was an error while loading. Please reload this page.