26
26
//! [ObjectStore::abort_multipart] is a no-op, since Azure Blob Store doesn't provide
27
27
//! a way to drop old blocks. Instead unused blocks are automatically cleaned up
28
28
//! after 7 days.
29
- use self :: client:: { BlockId , BlockList } ;
30
29
use crate :: {
31
30
multipart:: { PartId , PutPart , WriteMultiPart } ,
32
31
path:: Path ,
33
32
GetOptions , GetResult , ListResult , MultipartId , ObjectMeta , ObjectStore , PutResult , Result ,
34
33
} ;
35
34
use async_trait:: async_trait;
36
- use base64:: prelude:: BASE64_STANDARD ;
37
- use base64:: Engine ;
38
35
use bytes:: Bytes ;
39
36
use futures:: stream:: BoxStream ;
40
37
use std:: fmt:: Debug ;
@@ -53,6 +50,7 @@ mod credential;
53
50
/// [`CredentialProvider`] for [`MicrosoftAzure`]
54
51
pub type AzureCredentialProvider = Arc < dyn CredentialProvider < Credential = AzureCredential > > ;
55
52
use crate :: client:: header:: get_etag;
53
+ use crate :: multipart:: MultiPartStore ;
56
54
pub use builder:: { AzureConfigKey , MicrosoftAzureBuilder } ;
57
55
pub use credential:: AzureCredential ;
58
56
@@ -151,54 +149,52 @@ struct AzureMultiPartUpload {
151
149
152
150
#[ async_trait]
153
151
impl PutPart for AzureMultiPartUpload {
154
- async fn put_part ( & self , buf : Vec < u8 > , part_idx : usize ) -> Result < PartId > {
155
- let content_id = format ! ( "{part_idx:20}" ) ;
156
- let block_id: BlockId = content_id. clone ( ) . into ( ) ;
157
-
158
- self . client
159
- . put_request (
160
- & self . location ,
161
- Some ( buf. into ( ) ) ,
162
- true ,
163
- & [
164
- ( "comp" , "block" ) ,
165
- ( "blockid" , & BASE64_STANDARD . encode ( block_id) ) ,
166
- ] ,
167
- )
168
- . await ?;
152
+ async fn put_part ( & self , buf : Vec < u8 > , idx : usize ) -> Result < PartId > {
153
+ self . client . put_block ( & self . location , idx, buf. into ( ) ) . await
154
+ }
169
155
170
- Ok ( PartId { content_id } )
156
+ async fn complete ( & self , parts : Vec < PartId > ) -> Result < ( ) > {
157
+ self . client . put_block_list ( & self . location , parts) . await ?;
158
+ Ok ( ( ) )
171
159
}
160
+ }
172
161
173
- async fn complete ( & self , completed_parts : Vec < PartId > ) -> Result < ( ) > {
174
- let blocks = completed_parts
175
- . into_iter ( )
176
- . map ( |part| BlockId :: from ( part . content_id ) )
177
- . collect ( ) ;
162
+ # [ async_trait ]
163
+ impl MultiPartStore for MicrosoftAzure {
164
+ async fn create_multipart ( & self , _ : & Path ) -> Result < MultipartId > {
165
+ Ok ( String :: new ( ) )
166
+ }
178
167
179
- let block_list = BlockList { blocks } ;
180
- let block_xml = block_list. to_xml ( ) ;
168
+ async fn put_part (
169
+ & self ,
170
+ path : & Path ,
171
+ _: & MultipartId ,
172
+ part_idx : usize ,
173
+ data : Bytes ,
174
+ ) -> Result < PartId > {
175
+ self . client . put_block ( path, part_idx, data) . await
176
+ }
181
177
182
- self . client
183
- . put_request (
184
- & self . location ,
185
- Some ( block_xml . into ( ) ) ,
186
- true ,
187
- & [ ( "comp" , "blocklist" ) ] ,
188
- )
189
- . await ? ;
178
+ async fn complete_multipart (
179
+ & self ,
180
+ path : & Path ,
181
+ _ : & MultipartId ,
182
+ parts : Vec < PartId > ,
183
+ ) -> Result < PutResult > {
184
+ self . client . put_block_list ( path , parts ) . await
185
+ }
190
186
187
+ async fn abort_multipart ( & self , _: & Path , _: & MultipartId ) -> Result < ( ) > {
188
+ // There is no way to drop blocks that have been uploaded. Instead, they simply
189
+ // expire in 7 days.
191
190
Ok ( ( ) )
192
191
}
193
192
}
194
193
195
194
#[ cfg( test) ]
196
195
mod tests {
197
196
use super :: * ;
198
- use crate :: tests:: {
199
- copy_if_not_exists, get_opts, list_uses_directories_correctly, list_with_delimiter,
200
- put_get_delete_list_opts, rename_and_copy, stream_get,
201
- } ;
197
+ use crate :: tests:: * ;
202
198
203
199
#[ tokio:: test]
204
200
async fn azure_blob_test ( ) {
@@ -212,6 +208,7 @@ mod tests {
212
208
rename_and_copy ( & integration) . await ;
213
209
copy_if_not_exists ( & integration) . await ;
214
210
stream_get ( & integration) . await ;
211
+ multipart ( & integration, & integration) . await ;
215
212
}
216
213
217
214
#[ test]
0 commit comments