pub trait MultipartWrite:
Send
+ Sync
+ Unpin
+ 'static {
// Required methods
fn write_once(
&self,
size: u64,
body: Buffer,
) -> impl Future<Output = Result<Metadata>> + MaybeSend;
fn initiate_part(&self) -> impl Future<Output = Result<String>> + MaybeSend;
fn write_part(
&self,
upload_id: &str,
part_number: usize,
size: u64,
body: Buffer,
) -> impl Future<Output = Result<MultipartPart>> + MaybeSend;
fn complete_part(
&self,
upload_id: &str,
parts: &[MultipartPart],
) -> impl Future<Output = Result<Metadata>> + MaybeSend;
fn abort_part(
&self,
upload_id: &str,
) -> impl Future<Output = Result<()>> + MaybeSend;
}Expand description
MultipartWrite is used to implement oio::Write based on multipart
uploads. By implementing MultipartWrite, services don’t need to
care about the details of uploading parts.
§Architecture
The architecture after adopting MultipartWrite:
- Services impl
MultipartWrite MultipartWriterimplWrite- Expose
MultipartWriterasAccessor::Writer
§Notes
MultipartWrite has an oneshot optimization when write has been called only once:
w.write(bs).await?;
w.close().await?;We will use write_once instead of starting a new multipart upload.
§Requirements
Services that implement BlockWrite must fulfill the following requirements:
- Must be a http service that could accept
AsyncBody. - Don’t need initialization before writing.
- Block ID is generated by caller
BlockWriteinstead of services. - Complete block by an ordered block id list.
Required Methods§
Sourcefn write_once(
&self,
size: u64,
body: Buffer,
) -> impl Future<Output = Result<Metadata>> + MaybeSend
fn write_once( &self, size: u64, body: Buffer, ) -> impl Future<Output = Result<Metadata>> + MaybeSend
write_once is used to write the data to underlying storage at once.
MultipartWriter will call this API when:
- All the data has been written to the buffer and we can perform the upload at once.
Sourcefn initiate_part(&self) -> impl Future<Output = Result<String>> + MaybeSend
fn initiate_part(&self) -> impl Future<Output = Result<String>> + MaybeSend
initiate_part will call start a multipart upload and return the upload id.
MultipartWriter will call this when:
- the total size of data is unknown.
- the total size of data is known, but the size of current write is less than the total size.
Sourcefn write_part(
&self,
upload_id: &str,
part_number: usize,
size: u64,
body: Buffer,
) -> impl Future<Output = Result<MultipartPart>> + MaybeSend
fn write_part( &self, upload_id: &str, part_number: usize, size: u64, body: Buffer, ) -> impl Future<Output = Result<MultipartPart>> + MaybeSend
write_part will write a part of the data and returns the result
MultipartPart.
MultipartWriter will call this API and stores the result in order.
- part_number is the index of the part, starting from 0.
Sourcefn complete_part(
&self,
upload_id: &str,
parts: &[MultipartPart],
) -> impl Future<Output = Result<Metadata>> + MaybeSend
fn complete_part( &self, upload_id: &str, parts: &[MultipartPart], ) -> impl Future<Output = Result<Metadata>> + MaybeSend
complete_part will complete the multipart upload to build the final file.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".