flaneur2020 commented on code in PR #6283: URL: https://github.com/apache/opendal/pull/6283#discussion_r2240203400
########## integrations/object_store/src/backend/reader.rs: ########## @@ -0,0 +1,123 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::future::Future; +use std::sync::Arc; + +use bytes::Bytes; +use object_store::GetRange; +use object_store::ObjectStore; + +use futures::FutureExt; +use opendal::raw::*; +use opendal::Error; +use opendal::ErrorKind; +use opendal::*; + +use super::error::parse_error; + +/// ObjectStore reader +pub struct ObjectStoreReader { + bytes: Option<Bytes>, + meta: object_store::ObjectMeta, + args: OpRead, +} + +impl ObjectStoreReader { + pub(crate) async fn new( + store: Arc<dyn ObjectStore + 'static>, + path: &str, + args: OpRead, + ) -> Result<Self> { + let path = object_store::path::Path::from(path); + let opts = parse_read_args(&args)?; + let result = store.get_opts(&path, opts).await.map_err(parse_error)?; + let meta = result.meta.clone(); + let bytes = result.bytes().await.map_err(parse_error)?; + Ok(Self { + bytes: Some(bytes), + meta, + args, + }) + } + + pub(crate) fn rp(&self) -> RpRead { + let mut rp = RpRead::new().with_size(Some(self.meta.size)); + if !self.args.range().is_full() { + let range = self.args.range(); + let size = match range.size() { + Some(size) => size, + None => self.meta.size, + }; + rp = rp.with_range(Some( + BytesContentRange::default().with_range(range.offset(), range.offset() + size - 1), + )); + } + rp + } +} + +impl oio::Read for ObjectStoreReader { + fn read(&mut self) -> impl Future<Output = Result<Buffer>> + MaybeSend { Review Comment: changed the bytes into a `bytes_stream` in 7465f99dca -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@opendal.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org