Skip to content

Commit

Permalink
feat(types): fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
oowl committed Aug 23, 2023
1 parent 65a7651 commit 5be5a5e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
25 changes: 12 additions & 13 deletions core/src/types/operator/blocking_operator.rs
Expand Up @@ -238,7 +238,7 @@ impl BlockingOperator {
/// reading data lazily, please use [`BlockingOperator::reader`]
///
/// # Examples
///
///
/// ```no_run
/// # use anyhow::Result;
/// use opendal::BlockingOperator;
Expand All @@ -262,31 +262,30 @@ impl BlockingOperator {
Error::new(ErrorKind::IsADirectory, "read path is a directory")
.with_operation("BlockingOperator::read_with")
.with_context("service", inner.info().scheme().into_static())
.with_context("path", &path)
.with_context("path", &path),
);
}

let (rp, mut s) = inner.blocking_read(&path, args)?;
let mut buffer = Vec::with_capacity(rp.into_metadata().content_length() as usize);

match s.read_to_end(&mut buffer) {
Ok(n) => {
buffer.truncate(n);
Ok(buffer)
},
}
Err(err) => Err(
Error::new(ErrorKind::Unexpected, "blocking read_with failed")
.with_operation("BlockingOperator::read_with")
.with_context("service", inner.info().scheme().into_static())
.with_context("path", &path)
.set_source(err)
.with_operation("BlockingOperator::read_with")
.with_context("service", inner.info().scheme().into_static())
.with_context("path", &path)
.set_source(err),
),
}
},
))
}


/// Create a new reader which can read the whole path.
///
/// # Examples
Expand All @@ -307,7 +306,7 @@ impl BlockingOperator {
/// Create a new reader with extra options
///
/// # Examples
///
///
/// ```no_run
/// # use anyhow::Result;
/// use opendal::BlockingOperator;
Expand All @@ -331,12 +330,12 @@ impl BlockingOperator {
Error::new(ErrorKind::IsADirectory, "reader path is a directory")
.with_operation("BlockingOperator::reader_with")
.with_context("service", inner.info().scheme().into_static())
.with_context("path", &path)
.with_context("path", &path),
);
}

BlockingReader::create(inner.clone(), &path, args)
}
},
))
}

Expand Down Expand Up @@ -1049,4 +1048,4 @@ impl BlockingOperator {
},
))
}
}
}
10 changes: 8 additions & 2 deletions core/tests/behavior/blocking_write.rs
Expand Up @@ -298,7 +298,10 @@ 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.reader_with(&path).range(0..content.len() as u64).call()?;
let mut o = op
.reader_with(&path)
.range(0..content.len() as u64)
.call()?;

for _ in 0..100 {
match fuzzer.fuzz() {
Expand Down Expand Up @@ -373,7 +376,10 @@ 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.reader_with(&path).range(offset..offset + length).call()?;
let mut o = op
.reader_with(&path)
.range(offset..offset + length)
.call()?;

for _ in 0..100 {
match fuzzer.fuzz() {
Expand Down

0 comments on commit 5be5a5e

Please sign in to comment.