Skip to content

Add get_opts and get_ranges - #9

Closed
kylebarron wants to merge 9 commits into
roeap:mainfrom
kylebarron:kyle/new-methods
Closed

Add get_opts and get_ranges#9
kylebarron wants to merge 9 commits into
roeap:mainfrom
kylebarron:kyle/new-methods

Conversation

@kylebarron

Copy link
Copy Markdown
Contributor
  • The underlying get_opts returns a GetResult. So ideally it would be nice to return a Python object that wraps this GetResult so that in the future we could potentially stream a result into a Python AsyncIterator. However I don't think that would ever be possible because its bytes and into_stream consume self. And you can't have a Python method that consumes self.

    So I think the best approach is to currently return bytes and potentially in the future have a separate get_opts_stream method that returns an async iterator.

I had tried with

#[pyclass(name = "GetResult")]#[derive(Debug)]pubstructPyGetResult{rt:Arc<Runtime>,result:Arc<Mutex<GetResult>>,}#[pymethods]implPyGetResult{pubfnbytes(&self) -> PyResult<Cow<[u8]>>{let lock = self.rt.block_on(self.result.lock());let obj = self.rt.block_on(lock.bytes()).map_err(ObjectStoreError::from)?;Ok(Cow::Owned(obj.to_vec()))}pubfnbytes_async<'a>(&'aself,py:Python<'a>) -> PyResult<&PyAny>{
pyo3_asyncio::tokio::future_into_py(py,asyncmove{let obj = self.result.lock().await.bytes().await.map_err(ObjectStoreError::from)?;Ok(Cow::<[u8]>::Owned(obj.to_vec()))})}}

This is implemented on top of #6, and is expected to be reviewed after that.

@kylebarron

Copy link
Copy Markdown
ContributorAuthor

Closing because I implemented this in https://github.com/developmentseed/object-store-rs

@kylebarronkylebarron mentioned this pull request Oct 18, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@kylebarron