azure_storage_blobs/blob/operations/
get_block_list.rs1use crate::{blob::BlockWithSizeList, prelude::*};
2use azure_core::{headers::*, prelude::*, RequestId};
3use std::str::from_utf8;
4use time::OffsetDateTime;
5
6operation! {
7 GetBlockList,
8 client: BlobClient,
9 ?if_tags: IfTags,
10 ?block_list_type: BlockListType,
11 ?blob_versioning: BlobVersioning,
12 ?lease_id: LeaseId
13}
14
15impl GetBlockListBuilder {
16 pub fn into_future(mut self) -> GetBlockList {
17 Box::pin(async move {
18 let mut url = self.client.url()?;
19
20 url.query_pairs_mut().append_pair("comp", "blocklist");
21 self.blob_versioning.append_to_url_query(&mut url);
22
23 self.block_list_type
24 .unwrap_or(BlockListType::Committed)
25 .append_to_url_query(&mut url);
26
27 let mut headers = Headers::new();
28 headers.add(self.lease_id);
29 headers.add(self.if_tags);
30
31 let mut request =
32 BlobClient::finalize_request(url, azure_core::Method::Get, headers, None)?;
33
34 let response = self.client.send(&mut self.context, &mut request).await?;
35
36 let (_, headers, body) = response.deconstruct();
37 let body = body.collect().await?;
38
39 GetBlockListResponse::from_response(&headers, &body)
40 })
41 }
42}
43
44#[derive(Debug, Clone, PartialEq, Eq)]
45pub struct GetBlockListResponse {
46 pub etag: Option<String>,
47 pub last_modified: Option<OffsetDateTime>,
48 pub request_id: RequestId,
49 pub date: OffsetDateTime,
50 pub block_with_size_list: BlockWithSizeList,
51}
52
53impl GetBlockListResponse {
54 pub(crate) fn from_response(
55 headers: &Headers,
56 body: &[u8],
57 ) -> azure_core::Result<GetBlockListResponse> {
58 let etag = etag_from_headers_optional(headers)?;
59 let last_modified = last_modified_from_headers_optional(headers)?;
60 let request_id = request_id_from_headers(headers)?;
61 let date = date_from_headers(headers)?;
62
63 let body = from_utf8(body)?;
64 let block_with_size_list = BlockWithSizeList::try_from_xml(body)?;
65
66 Ok(GetBlockListResponse {
67 etag,
68 last_modified,
69 request_id,
70 date,
71 block_with_size_list,
72 })
73 }
74}