Skip to content

Commit

Permalink
finish framework
Browse files Browse the repository at this point in the history
  • Loading branch information
wcy-fdu committed Feb 14, 2024
1 parent 98c0597 commit 5ac1797
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 39 deletions.
21 changes: 10 additions & 11 deletions core/src/services/azblob/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
// under the License.

use bytes::Bytes;
use http::header::HeaderName;
use http::header::CONTENT_LENGTH;
use http::header::CONTENT_TYPE;
use http::header::IF_MATCH;
use http::header::IF_NONE_MATCH;
use http::HeaderValue;
use http::Request;
use http::Response;
use http::{header::HeaderName, StatusCode};
use reqsign::AzureStorageCredential;
use reqsign::AzureStorageLoader;
use reqsign::AzureStorageSigner;
Expand All @@ -39,8 +39,6 @@ use uuid::Uuid;
use crate::raw::*;
use crate::*;

use super::error::parse_error;

mod constants {
pub const X_MS_VERSION: &str = "x-ms-version";

Expand Down Expand Up @@ -381,6 +379,7 @@ impl AzblobCore {
args: &OpWrite,
body: AsyncBody,
) -> Result<Request<AsyncBody>> {
// refer to https://learn.microsoft.com/en-us/rest/api/storageservices/put-block-list?
let p = build_abs_path(&self.root, path);

let url = format!(
Expand Down Expand Up @@ -439,16 +438,16 @@ impl AzblobCore {
let req = self.insert_sse_headers(req);

// Set body
let mut req_body = "".to_string();
req_body.push_str("<BlockList>\n");
let req_body = {
let block_list = block_ids
.iter()
.map(|block_id| format!(" <Uncommitted>{}</Uncommitted>", block_id))
.collect::<Vec<String>>()
.join("\n");

for block_id in block_ids {
req_body.push_str("<Uncommitted>");
req_body.push_str(&block_id.to_string());
req_body.push_str("</Uncommitted>\n");
}
format!("<BlockList>\n{}\n</BlockList>", block_list)
};

req_body.push_str("</BlockList>");
let body = AsyncBody::Bytes(Bytes::from(req_body.to_string()));
let req = req.body(body).map_err(new_request_build_error)?;
Ok(req)
Expand Down
28 changes: 0 additions & 28 deletions core/src/services/azblob/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,6 @@ impl AzblobWriter {
}
}

#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl oio::OneShotWrite for AzblobWriter {
async fn write_once(&self, bs: &dyn oio::WriteBuf) -> Result<()> {
let bs = oio::ChunkedBytes::from_vec(bs.vectored_bytes(bs.remaining()));
let mut req = self.core.azblob_put_blob_request(
&self.path,
Some(bs.len() as u64),
&self.op,
AsyncBody::ChunkedBytes(bs),
)?;

self.core.sign(&mut req).await?;

let resp = self.core.send(req).await?;

let status = resp.status();

match status {
StatusCode::CREATED | StatusCode::OK => {
resp.into_body().consume().await?;
Ok(())
}
_ => Err(parse_error(resp).await?),
}
}
}

#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
impl oio::AppendWrite for AzblobWriter {
Expand Down

0 comments on commit 5ac1797

Please sign in to comment.