diff --git a/bindings/c/include/opendal.h b/bindings/c/include/opendal.h index 9c46b3321f2..d93713c33cb 100644 --- a/bindings/c/include/opendal.h +++ b/bindings/c/include/opendal.h @@ -146,6 +146,12 @@ typedef struct BlockingLister BlockingLister; */ typedef struct BlockingOperator BlockingOperator; +/** + * BlockingWriter is designed to write data into given path in an blocking + * manner. + */ +typedef struct BlockingWriter BlockingWriter; + /** * Entry returned by [`Lister`] or [`BlockingLister`] to represent a path and it's relative metadata. * @@ -216,18 +222,6 @@ typedef struct OperatorInfo OperatorInfo; */ typedef struct StdReader StdReader; -/** - * StdWriter is the adapter of [`std::io::Write`] for [`BlockingWriter`]. - * - * Users can use this adapter in cases where they need to use [`std::io::Write`] related trait. - * - * # Notes - * - * Files are automatically closed when they go out of scope. Errors detected on closing are ignored - * by the implementation of Drop. Use the method `close` if these errors must be manually handled. - */ -typedef struct StdWriter StdWriter; - /** * \brief opendal_bytes carries raw-bytes with its length * @@ -448,7 +442,7 @@ typedef struct opendal_result_operator_reader { * a opendal::BlockingWriter, which is inside the Rust core code. */ typedef struct opendal_writer { - struct StdWriter *inner; + struct BlockingWriter *inner; } opendal_writer; /** diff --git a/bindings/c/src/operator.rs b/bindings/c/src/operator.rs index c1af1e57179..ebfca45fdcc 100644 --- a/bindings/c/src/operator.rs +++ b/bindings/c/src/operator.rs @@ -449,7 +449,7 @@ pub unsafe extern "C" fn opendal_operator_writer( }; opendal_result_operator_writer { - writer: Box::into_raw(Box::new(opendal_writer::new(writer.into_std_write()))), + writer: Box::into_raw(Box::new(opendal_writer::new(writer))), error: std::ptr::null_mut(), } } diff --git a/bindings/c/src/writer.rs b/bindings/c/src/writer.rs index d78f676427c..186185176cc 100644 --- a/bindings/c/src/writer.rs +++ b/bindings/c/src/writer.rs @@ -15,10 +15,7 @@ // specific language governing permissions and limitations // under the License. -use std::io::Write; - use ::opendal as core; -use opendal::Buffer; use super::*; @@ -27,11 +24,11 @@ use super::*; /// a opendal::BlockingWriter, which is inside the Rust core code. #[repr(C)] pub struct opendal_writer { - inner: *mut core::StdWriter, + inner: *mut core::BlockingWriter, } impl opendal_writer { - pub(crate) fn new(writer: core::StdWriter) -> Self { + pub(crate) fn new(writer: core::BlockingWriter) -> Self { Self { inner: Box::into_raw(Box::new(writer)), } @@ -44,11 +41,10 @@ impl opendal_writer { bytes: opendal_bytes, ) -> opendal_result_writer_write { let inner = unsafe { &mut *(*writer).inner }; - let buf: Buffer = bytes.into(); - let n = inner.write(&buf.to_vec()); - match n { - Ok(n) => opendal_result_writer_write { - size: n, + let size = bytes.len; + match inner.write(bytes) { + Ok(()) => opendal_result_writer_write { + size, error: std::ptr::null_mut(), }, Err(e) => opendal_result_writer_write { diff --git a/bindings/go/tests/behavior_tests/write_test.go b/bindings/go/tests/behavior_tests/write_test.go index 2b7626a43e2..05d626972d5 100644 --- a/bindings/go/tests/behavior_tests/write_test.go +++ b/bindings/go/tests/behavior_tests/write_test.go @@ -107,8 +107,7 @@ func testWriterWrite(assert *require.Assertions, op *opendal.Operator, fixture * } path := fixture.NewFilePath() - // StdWriter capacity is 256KB - size := uint(256 * 1024) + size := uint(5 * 1024 * 1024) contentA := genFixedBytes(size) contentB := genFixedBytes(size)