This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 04cb5f085 feat(services/webdav): impl sink (#2622)
04cb5f085 is described below

commit 04cb5f085474584be5ffc7f40137fa0f11586728
Author: Suyan <[email protected]>
AuthorDate: Wed Jul 12 23:09:32 2023 +0800

    feat(services/webdav): impl sink (#2622)
---
 core/src/services/webdav/backend.rs |  6 +++++-
 core/src/services/webdav/writer.rs  | 24 +++++++++++++-----------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/core/src/services/webdav/backend.rs 
b/core/src/services/webdav/backend.rs
index fbc323c82..825e2f067 100644
--- a/core/src/services/webdav/backend.rs
+++ b/core/src/services/webdav/backend.rs
@@ -277,9 +277,13 @@ impl Accessor for WebdavBackend {
                 read_with_range: true,
 
                 write: true,
+                write_can_sink: true,
+
                 create_dir: true,
                 delete: true,
+
                 copy: true,
+
                 rename: true,
 
                 list: true,
@@ -471,7 +475,7 @@ impl WebdavBackend {
     pub async fn webdav_put(
         &self,
         abs_path: &str,
-        size: Option<usize>,
+        size: Option<u64>,
         content_type: Option<&str>,
         content_disposition: Option<&str>,
         body: AsyncBody,
diff --git a/core/src/services/webdav/writer.rs 
b/core/src/services/webdav/writer.rs
index 5ccccba57..a3c17bafa 100644
--- a/core/src/services/webdav/writer.rs
+++ b/core/src/services/webdav/writer.rs
@@ -35,19 +35,16 @@ impl WebdavWriter {
     pub fn new(backend: WebdavBackend, op: OpWrite, path: String) -> Self {
         WebdavWriter { backend, op, path }
     }
-}
 
-#[async_trait]
-impl oio::Write for WebdavWriter {
-    async fn write(&mut self, bs: Bytes) -> Result<()> {
+    async fn write_oneshot(&mut self, size: u64, body: AsyncBody) -> 
Result<()> {
         let resp = self
             .backend
             .webdav_put(
                 &self.path,
-                Some(bs.len()),
+                Some(size),
                 self.op.content_type(),
                 self.op.content_disposition(),
-                AsyncBody::Bytes(bs),
+                body,
             )
             .await?;
 
@@ -61,12 +58,17 @@ impl oio::Write for WebdavWriter {
             _ => Err(parse_error(resp).await?),
         }
     }
+}
+
+#[async_trait]
+impl oio::Write for WebdavWriter {
+    async fn write(&mut self, bs: Bytes) -> Result<()> {
+        self.write_oneshot(bs.len() as u64, AsyncBody::Bytes(bs))
+            .await
+    }
 
-    async fn sink(&mut self, _size: u64, _s: oio::Streamer) -> Result<()> {
-        Err(Error::new(
-            ErrorKind::Unsupported,
-            "Write::sink is not supported",
-        ))
+    async fn sink(&mut self, size: u64, s: oio::Streamer) -> Result<()> {
+        self.write_oneshot(size, AsyncBody::Stream(s)).await
     }
 
     async fn abort(&mut self) -> Result<()> {

Reply via email to