Skip to content

Commit 324ca1a

Browse files
committed
async-multipart: impl Stream for Multipart<Bytes>
1 parent cbbcf29 commit 324ca1a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/v1/objects/insert.rs

+24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
use futures_util::{
99
io::{AsyncRead, Result as FuturesResult},
1010
task::{Context, Poll},
11+
Stream,
1112
};
1213
#[cfg(feature = "async-multipart")]
1314
use pin_utils::unsafe_pinned;
@@ -293,6 +294,29 @@ impl<B: AsyncRead + Unpin> AsyncRead for Multipart<B> {
293294
}
294295
}
295296

297+
#[cfg(feature = "async-multipart")]
298+
impl Stream for Multipart<bytes::Bytes> {
299+
type Item = bytes::Bytes;
300+
301+
fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
302+
Poll::Ready(match self.cursor.part {
303+
MultipartPart::Prefix => {
304+
self.cursor.part.next();
305+
Some(self.prefix.clone())
306+
}
307+
MultipartPart::Body => {
308+
self.cursor.part.next();
309+
Some(self.body.clone())
310+
}
311+
MultipartPart::Suffix => {
312+
self.cursor.part.next();
313+
Some(bytes::Bytes::from(MULTI_PART_SUFFIX))
314+
}
315+
MultipartPart::End => None,
316+
})
317+
}
318+
}
319+
296320
impl super::Object {
297321
/// Stores a new object and metadata.
298322
///

0 commit comments

Comments
 (0)