Skip to content

Commit

Permalink
feat(services/webdav): impl sink (#2622)
Browse files Browse the repository at this point in the history
  • Loading branch information
suyanhanx committed Jul 12, 2023
1 parent c09efd1 commit 04cb5f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 5 additions & 1 deletion core/src/services/webdav/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 13 additions & 11 deletions core/src/services/webdav/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand All @@ -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<()> {
Expand Down

0 comments on commit 04cb5f0

Please sign in to comment.