Trait opendal::raw::oio::MultipartWrite

source ·
pub trait MultipartWrite: Send + Sync + Unpin + 'static {
    // Required methods
    fn write_once(
        &self,
        size: u64,
        body: Buffer
    ) -> impl Future<Output = Result<()>> + 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<()>> + MaybeSend;
    fn abort_part(
        &self,
        upload_id: &str
    ) -> impl Future<Output = Result<()>> + MaybeSend;
}
Expand description

MultipartWrite is used to implement [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
  • MultipartWriter impl Write
  • Expose MultipartWriter as Accessor::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 BlockWrite instead of services.
  • Complete block by an ordered block id list.

Required Methods§

source

fn write_once( &self, size: u64, body: Buffer ) -> impl Future<Output = Result<()>> + 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.
source

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 then the total size.
source

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.
source

fn complete_part( &self, upload_id: &str, parts: &[MultipartPart] ) -> impl Future<Output = Result<()>> + MaybeSend

complete_part will complete the multipart upload to build the final file.

source

fn abort_part( &self, upload_id: &str ) -> impl Future<Output = Result<()>> + MaybeSend

abort_part will cancel the multipart upload and purge all data.

Object Safety§

This trait is not object safe.

Implementors§