Skip to content

Use latest main of object_store #12

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

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ flate2 = "1.0.20"
futures = "0.3.31"
jpeg = { package = "jpeg-decoder", version = "0.3.0", default-features = false }
num_enum = "0.7.3"
object_store = "0.11"
# Match the version used by pyo3-object-store
object_store = { git = "https://github.com/apache/arrow-rs", rev = "7a15e4b47ca97df2edef689c9f2ebd2f3888b79e" }
thiserror = "1"
tiff = "0.9"
tokio = { version = "1.43.0", optional = true }
Expand Down
20 changes: 10 additions & 10 deletions src/async_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use crate::error::{AiocogeoError, Result};
/// [`tokio::fs::File`]: https://docs.rs/tokio/latest/tokio/fs/struct.File.html
pub trait AsyncFileReader: Send {
/// Retrieve the bytes in `range`
fn get_bytes(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>>;
fn get_bytes(&mut self, range: Range<u64>) -> BoxFuture<'_, Result<Bytes>>;

/// Retrieve multiple byte ranges. The default implementation will call `get_bytes` sequentially
fn get_byte_ranges(&mut self, ranges: Vec<Range<usize>>) -> BoxFuture<'_, Result<Vec<Bytes>>> {
fn get_byte_ranges(&mut self, ranges: Vec<Range<u64>>) -> BoxFuture<'_, Result<Vec<Bytes>>> {
async move {
let mut result = Vec::with_capacity(ranges.len());

Expand All @@ -47,24 +47,24 @@ pub trait AsyncFileReader: Send {

/// This allows Box<dyn AsyncFileReader + '_> to be used as an AsyncFileReader,
impl AsyncFileReader for Box<dyn AsyncFileReader + '_> {
fn get_bytes(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>> {
fn get_bytes(&mut self, range: Range<u64>) -> BoxFuture<'_, Result<Bytes>> {
self.as_mut().get_bytes(range)
}

fn get_byte_ranges(&mut self, ranges: Vec<Range<usize>>) -> BoxFuture<'_, Result<Vec<Bytes>>> {
fn get_byte_ranges(&mut self, ranges: Vec<Range<u64>>) -> BoxFuture<'_, Result<Vec<Bytes>>> {
self.as_mut().get_byte_ranges(ranges)
}
}

#[cfg(feature = "tokio")]
impl<T: tokio::io::AsyncRead + tokio::io::AsyncSeek + Unpin + Send> AsyncFileReader for T {
fn get_bytes(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>> {
fn get_bytes(&mut self, range: Range<u64>) -> BoxFuture<'_, Result<Bytes>> {
use tokio::io::{AsyncReadExt, AsyncSeekExt};

async move {
self.seek(SeekFrom::Start(range.start as u64)).await?;
self.seek(SeekFrom::Start(range.start)).await?;

let to_read = range.end - range.start;
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 {
Expand Down Expand Up @@ -93,14 +93,14 @@ impl ObjectReader {
}

impl AsyncFileReader for ObjectReader {
fn get_bytes(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>> {
fn get_bytes(&mut self, range: Range<u64>) -> BoxFuture<'_, Result<Bytes>> {
self.store
.get_range(&self.path, range)
.map_err(|e| e.into())
.boxed()
}

fn get_byte_ranges(&mut self, ranges: Vec<Range<usize>>) -> BoxFuture<'_, Result<Vec<Bytes>>>
fn get_byte_ranges(&mut self, ranges: Vec<Range<u64>>) -> BoxFuture<'_, Result<Vec<Bytes>>>
where
Self: Send,
{
Expand Down Expand Up @@ -160,7 +160,7 @@ impl AsyncCursor {
}

pub(crate) async fn read(&mut self, length: usize) -> Bytes {
let range = self.offset..self.offset + length;
let range = self.offset as _..(self.offset + length) as _;
self.offset += length;
self.reader.get_bytes(range).await.unwrap()
}
Expand Down
4 changes: 2 additions & 2 deletions src/ifd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,12 @@ impl ImageFileDirectory {
}
}

fn get_tile_byte_range(&self, x: usize, y: usize) -> Range<usize> {
fn get_tile_byte_range(&self, x: usize, y: usize) -> Range<u64> {
let idx = (y * self.tile_count().0) + x;
let offset = self.tile_offsets[idx] as usize;
// TODO: aiocogeo has a -1 here, but I think that was in error
let byte_count = self.tile_byte_counts[idx] as usize;
offset..offset + byte_count
offset as _..(offset + byte_count) as _
}

pub async fn get_tile(
Expand Down