Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(services/obs): support sink #2578

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/services/obs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ impl Accessor for ObsBackend {
read_with_if_none_match: true,

write: true,
write_can_sink: true,
write_with_content_type: true,
write_with_cache_control: true,

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/obs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl ObsCore {
pub fn obs_put_object_request(
&self,
path: &str,
size: Option<usize>,
size: Option<u64>,
content_type: Option<&str>,
cache_control: Option<&str>,
body: AsyncBody,
Expand Down
24 changes: 13 additions & 11 deletions core/src/services/obs/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,14 @@ impl ObsWriter {
pub fn new(core: Arc<ObsCore>, op: OpWrite, path: String) -> Self {
ObsWriter { core, op, path }
}
}

#[async_trait]
impl oio::Write for ObsWriter {
async fn write(&mut self, bs: Bytes) -> Result<()> {
async fn write_oneshot(&self, size: u64, body: AsyncBody) -> Result<()> {
let mut req = self.core.obs_put_object_request(
&self.path,
Some(bs.len()),
Some(size),
self.op.content_type(),
self.op.cache_control(),
AsyncBody::Bytes(bs),
body,
)?;

self.core.sign(&mut req).await?;
Expand All @@ -64,12 +61,17 @@ impl oio::Write for ObsWriter {
_ => Err(parse_error(resp).await?),
}
}
}

#[async_trait]
impl oio::Write for ObsWriter {
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