azure_storage_blob/models/
download_result.rs1use azure_core::{
5 base64,
6 fmt::SafeDebug,
7 http::{
8 headers::{HeaderName, Headers},
9 response::AsyncResponseBody,
10 AsyncRawResponse, Etag,
11 },
12 time::parse_rfc7231,
13};
14use std::collections::HashMap;
15use time::OffsetDateTime;
16
17use crate::generated::models::{
18 BlobType, CopyStatus, ImmutabilityPolicyMode, LeaseDuration, LeaseState, LeaseStatus,
19};
20
21#[derive(SafeDebug)]
27pub struct BlobClientDownloadResult {
28 pub body: AsyncResponseBody,
30
31 pub properties: BlobDownloadProperties,
33
34 pub headers: Headers,
39}
40
41#[derive(SafeDebug)]
43pub struct BlobClientDownloadIntoResult {
44 pub len: usize,
46
47 pub properties: BlobDownloadProperties,
49
50 pub headers: Headers,
55}
56
57#[derive(SafeDebug)]
59pub struct BlobDownloadProperties {
60 pub etag: Option<Etag>,
62
63 pub last_modified: Option<OffsetDateTime>,
65
66 pub created_on: Option<OffsetDateTime>,
68
69 pub last_accessed: Option<OffsetDateTime>,
71
72 pub content_length: Option<u64>,
77
78 pub content_type: Option<String>,
80
81 pub cache_control: Option<String>,
83
84 pub content_disposition: Option<String>,
86
87 pub content_encoding: Option<String>,
89
90 pub content_language: Option<String>,
92
93 pub content_md5: Option<Vec<u8>>,
99
100 pub content_crc64: Option<Vec<u8>>,
106
107 pub blob_content_md5: Option<Vec<u8>>,
112
113 pub blob_type: Option<BlobType>,
115
116 pub blob_sequence_number: Option<i64>,
118
119 pub blob_committed_block_count: Option<i32>,
122
123 pub is_sealed: Option<bool>,
125
126 pub metadata: HashMap<String, String>,
128
129 pub version_id: Option<String>,
131
132 pub lease_state: Option<LeaseState>,
134
135 pub lease_status: Option<LeaseStatus>,
137
138 pub lease_duration: Option<LeaseDuration>,
140
141 pub legal_hold: Option<bool>,
143
144 pub immutability_policy_mode: Option<ImmutabilityPolicyMode>,
146
147 pub immutability_policy_expires_on: Option<OffsetDateTime>,
149
150 pub copy_completed_on: Option<OffsetDateTime>,
152
153 pub copy_id: Option<String>,
155
156 pub copy_progress: Option<String>,
158
159 pub copy_source: Option<String>,
161
162 pub copy_status: Option<CopyStatus>,
164
165 pub copy_status_description: Option<String>,
167
168 pub object_replication_policy_id: Option<String>,
170
171 pub object_replication_rules: HashMap<String, String>,
173
174 pub tag_count: Option<i64>,
176
177 pub encryption_scope: Option<String>,
179
180 pub encryption_key_sha256: Option<String>,
183}
184
185impl BlobClientDownloadResult {
186 pub(crate) fn from_headers(response: AsyncRawResponse) -> azure_core::Result<Self> {
188 let (_, headers, body) = response.deconstruct();
189 let properties = BlobDownloadProperties::from_headers(&headers)?;
190 Ok(Self {
191 body,
192 properties,
193 headers,
194 })
195 }
196}
197
198impl BlobDownloadProperties {
199 pub(crate) fn from_headers(headers: &Headers) -> azure_core::Result<Self> {
200 let (metadata, object_replication_rules) =
201 crate::parsers::parse_metadata_and_replication_headers(headers);
202 Ok(Self {
203 etag: headers.get_optional_as(&HeaderName::from_static("etag"))?,
204 last_modified: headers
205 .get_optional_with(&HeaderName::from_static("last-modified"), |h| {
206 parse_rfc7231(h.as_str())
207 })?,
208 created_on: headers
209 .get_optional_with(&HeaderName::from_static("x-ms-creation-time"), |h| {
210 parse_rfc7231(h.as_str())
211 })?,
212 last_accessed: headers
213 .get_optional_with(&HeaderName::from_static("x-ms-last-access-time"), |h| {
214 parse_rfc7231(h.as_str())
215 })?,
216 content_length: headers.get_optional_as(&HeaderName::from_static("content-length"))?,
217 content_type: headers.get_optional_as(&HeaderName::from_static("content-type"))?,
218 cache_control: headers.get_optional_as(&HeaderName::from_static("cache-control"))?,
219 content_disposition: headers
220 .get_optional_as(&HeaderName::from_static("content-disposition"))?,
221 content_encoding: headers
222 .get_optional_as(&HeaderName::from_static("content-encoding"))?,
223 content_language: headers
224 .get_optional_as(&HeaderName::from_static("content-language"))?,
225 content_md5: headers
226 .get_optional_with(&HeaderName::from_static("content-md5"), |h| {
227 base64::decode(h.as_str())
228 })?,
229 content_crc64: headers
230 .get_optional_with(&HeaderName::from_static("x-ms-content-crc64"), |h| {
231 base64::decode(h.as_str())
232 })?,
233 blob_content_md5: headers
234 .get_optional_with(&HeaderName::from_static("x-ms-blob-content-md5"), |h| {
235 base64::decode(h.as_str())
236 })?,
237 blob_type: headers.get_optional_as(&HeaderName::from_static("x-ms-blob-type"))?,
238 blob_sequence_number: headers
239 .get_optional_as(&HeaderName::from_static("x-ms-blob-sequence-number"))?,
240 blob_committed_block_count: headers
241 .get_optional_as(&HeaderName::from_static("x-ms-blob-committed-block-count"))?,
242 is_sealed: headers.get_optional_as(&HeaderName::from_static("x-ms-blob-sealed"))?,
243 version_id: headers.get_optional_as(&HeaderName::from_static("x-ms-version-id"))?,
244 lease_state: headers.get_optional_as(&HeaderName::from_static("x-ms-lease-state"))?,
245 lease_status: headers.get_optional_as(&HeaderName::from_static("x-ms-lease-status"))?,
246 lease_duration: headers
247 .get_optional_as(&HeaderName::from_static("x-ms-lease-duration"))?,
248 legal_hold: headers.get_optional_as(&HeaderName::from_static("x-ms-legal-hold"))?,
249 immutability_policy_mode: headers
250 .get_optional_as(&HeaderName::from_static("x-ms-immutability-policy-mode"))?,
251 immutability_policy_expires_on: headers.get_optional_with(
252 &HeaderName::from_static("x-ms-immutability-policy-until-date"),
253 |h| parse_rfc7231(h.as_str()),
254 )?,
255 copy_completed_on: headers
256 .get_optional_with(&HeaderName::from_static("x-ms-copy-completion-time"), |h| {
257 parse_rfc7231(h.as_str())
258 })?,
259 copy_id: headers.get_optional_as(&HeaderName::from_static("x-ms-copy-id"))?,
260 copy_progress: headers
261 .get_optional_as(&HeaderName::from_static("x-ms-copy-progress"))?,
262 copy_source: headers.get_optional_as(&HeaderName::from_static("x-ms-copy-source"))?,
263 copy_status: headers.get_optional_as(&HeaderName::from_static("x-ms-copy-status"))?,
264 copy_status_description: headers
265 .get_optional_as(&HeaderName::from_static("x-ms-copy-status-description"))?,
266 object_replication_policy_id: headers
267 .get_optional_as(&HeaderName::from_static("x-ms-or-policy-id"))?,
268 tag_count: headers.get_optional_as(&HeaderName::from_static("x-ms-tag-count"))?,
269 encryption_scope: headers
270 .get_optional_as(&HeaderName::from_static("x-ms-encryption-scope"))?,
271 encryption_key_sha256: headers
272 .get_optional_as(&HeaderName::from_static("x-ms-encryption-key-sha256"))?,
273 metadata,
274 object_replication_rules,
275 })
276 }
277}