object-store-python
object-store-python copied to clipboard
Add `get_opts` and `get_ranges`
-
The underlying
get_optsreturns aGetResult. So ideally it would be nice to return a Python object that wraps thisGetResultso 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 itsbytesandinto_streamconsumeself. And you can't have a Python method that consumesself.So I think the best approach is to currently return
bytesand potentially in the future have a separateget_opts_streammethod that returns an async iterator.
I had tried with
#[pyclass(name = "GetResult")]
#[derive(Debug)]
pub struct PyGetResult {
rt: Arc<Runtime>,
result: Arc<Mutex<GetResult>>,
}
#[pymethods]
impl PyGetResult {
pub fn bytes(&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()))
}
pub fn bytes_async<'a>(&'a self, py: Python<'a>) -> PyResult<&PyAny> {
pyo3_asyncio::tokio::future_into_py(py, async move {
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.