From 324ca1a0a01846d532e66e86d4091195fa910a62 Mon Sep 17 00:00:00 2001 From: shikhar Date: Sun, 18 Jul 2021 23:20:44 -0400 Subject: [PATCH] async-multipart: impl Stream for Multipart --- src/v1/objects/insert.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/v1/objects/insert.rs b/src/v1/objects/insert.rs index 0a02dc8..99a7d9d 100644 --- a/src/v1/objects/insert.rs +++ b/src/v1/objects/insert.rs @@ -8,6 +8,7 @@ use crate::{ use futures_util::{ io::{AsyncRead, Result as FuturesResult}, task::{Context, Poll}, + Stream, }; #[cfg(feature = "async-multipart")] use pin_utils::unsafe_pinned; @@ -293,6 +294,29 @@ impl AsyncRead for Multipart { } } +#[cfg(feature = "async-multipart")] +impl Stream for Multipart { + type Item = bytes::Bytes; + + fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { + Poll::Ready(match self.cursor.part { + MultipartPart::Prefix => { + self.cursor.part.next(); + Some(self.prefix.clone()) + } + MultipartPart::Body => { + self.cursor.part.next(); + Some(self.body.clone()) + } + MultipartPart::Suffix => { + self.cursor.part.next(); + Some(bytes::Bytes::from(MULTI_PART_SUFFIX)) + } + MultipartPart::End => None, + }) + } +} + impl super::Object { /// Stores a new object and metadata. ///