This is an automated email from the ASF dual-hosted git repository.
junouyang pushed a commit to branch feat/blockong-operator-range-read
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to
refs/heads/feat/blockong-operator-range-read by this push:
new 786506e79 feat(types): remove blocking operator range_read and
range_reader API
786506e79 is described below
commit 786506e79c2adb4341f771f95f0c3de4622492ed
Author: owl <[email protected]>
AuthorDate: Wed Aug 23 17:45:04 2023 +0800
feat(types): remove blocking operator range_read and range_reader API
---
core/src/types/operator/blocking_operator.rs | 82 +---------------------------
core/tests/behavior/blocking_read_only.rs | 6 +-
core/tests/behavior/blocking_write.rs | 10 ++--
3 files changed, 10 insertions(+), 88 deletions(-)
diff --git a/core/src/types/operator/blocking_operator.rs
b/core/src/types/operator/blocking_operator.rs
index 012a27df4..255c92107 100644
--- a/core/src/types/operator/blocking_operator.rs
+++ b/core/src/types/operator/blocking_operator.rs
@@ -16,7 +16,6 @@
// under the License.
use std::io::Read;
-use std::ops::RangeBounds;
use bytes::Bytes;
@@ -230,54 +229,7 @@ impl BlockingOperator {
/// # }
/// ```
pub fn read(&self, path: &str) -> Result<Vec<u8>> {
- self.range_read(path, ..)
- }
-
- /// Read the specified range of path into a bytes.
- ///
- /// This function will allocate a new bytes internally. For more precise
memory control or
- /// reading data lazily, please use [`BlockingOperator::range_reader`]
- ///
- /// # Examples
- ///
- /// ```no_run
- /// # use std::io::Result;
- /// # use opendal::BlockingOperator;
- /// # use futures::TryStreamExt;
- /// # use opendal::Scheme;
- /// # fn test(op: BlockingOperator) -> Result<()> {
- /// let bs = op.range_read("path/to/file", 1024..2048)?;
- /// # Ok(())
- /// # }
- /// ```
- pub fn range_read(&self, path: &str, range: impl RangeBounds<u64>) ->
Result<Vec<u8>> {
- let path = normalize_path(path);
-
- if !validate_path(&path, EntryMode::FILE) {
- return Err(
- Error::new(ErrorKind::IsADirectory, "read path is a directory")
- .with_operation("BlockingOperator::range_read")
- .with_context("service",
self.info().scheme().into_static())
- .with_context("path", &path),
- );
- }
-
- let br = BytesRange::from(range);
- let (rp, mut s) = self
- .inner()
- .blocking_read(&path, OpRead::new().with_range(br))?;
-
- let mut buffer =
Vec::with_capacity(rp.into_metadata().content_length() as usize);
- s.read_to_end(&mut buffer).map_err(|err| {
- Error::new(ErrorKind::Unexpected, "blocking range read failed")
- .with_operation("BlockingOperator::range_read")
- .with_context("service", self.info().scheme().into_static())
- .with_context("path", path)
- .with_context("range", br.to_string())
- .set_source(err)
- })?;
-
- Ok(buffer)
+ self.read_with(path).call()
}
/// Read the whole path into a bytes with extra options.
@@ -349,37 +301,7 @@ impl BlockingOperator {
/// # }
/// ```
pub fn reader(&self, path: &str) -> Result<BlockingReader> {
- self.range_reader(path, ..)
- }
-
- /// Create a new reader which can read the specified range.
- ///
- /// # Examples
- ///
- /// ```no_run
- /// # use std::io::Result;
- /// # use opendal::BlockingOperator;
- /// # use futures::TryStreamExt;
- /// # fn test(op: BlockingOperator) -> Result<()> {
- /// let r = op.range_reader("path/to/file", 1024..2048)?;
- /// # Ok(())
- /// # }
- /// ```
- pub fn range_reader(&self, path: &str, range: impl RangeBounds<u64>) ->
Result<BlockingReader> {
- let path = normalize_path(path);
-
- if !validate_path(&path, EntryMode::FILE) {
- return Err(
- Error::new(ErrorKind::IsADirectory, "read path is a directory")
- .with_operation("BlockingOperator::range_reader")
- .with_context("service",
self.info().scheme().into_static())
- .with_context("path", &path),
- );
- }
-
- let op = OpRead::new().with_range(range.into());
-
- BlockingReader::create(self.inner().clone(), &path, op)
+ self.reader_with(path).call()
}
/// Create a new reader with extra options
diff --git a/core/tests/behavior/blocking_read_only.rs
b/core/tests/behavior/blocking_read_only.rs
index 6c4f5e0ab..f351d13bf 100644
--- a/core/tests/behavior/blocking_read_only.rs
+++ b/core/tests/behavior/blocking_read_only.rs
@@ -34,7 +34,7 @@ pub fn behavior_blocking_read_only_tests(op: &Operator) ->
Vec<Trial> {
test_blocking_read_only_stat_special_chars,
test_blocking_read_only_stat_not_exist,
test_blocking_read_only_read_full,
- test_blocking_read_only_read_range,
+ test_blocking_read_only_read_with_range,
test_blocking_read_only_read_not_exist
)
}
@@ -88,8 +88,8 @@ pub fn test_blocking_read_only_read_full(op:
BlockingOperator) -> Result<()> {
}
/// Read full content should match.
-pub fn test_blocking_read_only_read_range(op: BlockingOperator) -> Result<()> {
- let bs = op.range_read("normal_file", 1024..2048)?;
+pub fn test_blocking_read_only_read_with_range(op: BlockingOperator) ->
Result<()> {
+ let bs = op.read_with("normal_file").range(1024..2048).call()?;
assert_eq!(bs.len(), 1024, "read size");
assert_eq!(
format!("{:x}", Sha256::digest(&bs)),
diff --git a/core/tests/behavior/blocking_write.rs
b/core/tests/behavior/blocking_write.rs
index 06d44a1b9..3445762d7 100644
--- a/core/tests/behavior/blocking_write.rs
+++ b/core/tests/behavior/blocking_write.rs
@@ -229,7 +229,7 @@ pub fn test_blocking_read_range(op: BlockingOperator) ->
Result<()> {
op.write(&path, content.clone())
.expect("write must succeed");
- let bs = op.range_read(&path, offset..offset + length)?;
+ let bs = op.read_with(&path).range(offset..offset + length).call()?;
assert_eq!(bs.len() as u64, length, "read size");
assert_eq!(
format!("{:x}", Sha256::digest(&bs)),
@@ -258,7 +258,7 @@ pub fn test_blocking_read_large_range(op: BlockingOperator)
-> Result<()> {
op.write(&path, content.clone())
.expect("write must succeed");
- let bs = op.range_read(&path, offset..u32::MAX as u64)?;
+ let bs = op.read_with(&path).range(offset..u32::MAX as u64).call()?;
assert_eq!(
bs.len() as u64,
size as u64 - offset,
@@ -298,7 +298,7 @@ pub fn test_blocking_fuzz_range_reader(op:
BlockingOperator) -> Result<()> {
.expect("write must succeed");
let mut fuzzer = ObjectReaderFuzzer::new(&path, content.clone(), 0,
content.len());
- let mut o = op.range_reader(&path, 0..content.len() as u64)?;
+ let mut o = op.reader_with(&path).range(0..content.len() as u64).call()?;
for _ in 0..100 {
match fuzzer.fuzz() {
@@ -335,7 +335,7 @@ pub fn test_blocking_fuzz_offset_reader(op:
BlockingOperator) -> Result<()> {
.expect("write must succeed");
let mut fuzzer = ObjectReaderFuzzer::new(&path, content.clone(), 0,
content.len());
- let mut o = op.range_reader(&path, 0..)?;
+ let mut o = op.reader_with(&path).range(0..).call()?;
for _ in 0..100 {
match fuzzer.fuzz() {
@@ -373,7 +373,7 @@ pub fn test_blocking_fuzz_part_reader(op: BlockingOperator)
-> Result<()> {
.expect("write must succeed");
let mut fuzzer = ObjectReaderFuzzer::new(&path, content, offset as usize,
length as usize);
- let mut o = op.range_reader(&path, offset..offset + length)?;
+ let mut o = op.reader_with(&path).range(offset..offset + length).call()?;
for _ in 0..100 {
match fuzzer.fuzz() {