[refactor-block] move read_stream_to_end to garage_net

This commit is contained in:
Alex Auvolat
2024-02-23 11:46:57 +01:00
parent 93552b9275
commit 9b41f4ff20
3 changed files with 28 additions and 18 deletions
+13
View File
@@ -3,6 +3,8 @@ use std::collections::VecDeque;
use bytes::BytesMut;
use crate::stream::ByteStream;
pub use bytes::Bytes;
/// A circular buffer of bytes, internally represented as a list of Bytes
@@ -119,6 +121,17 @@ impl BytesBuf {
pub fn into_slices(self) -> VecDeque<Bytes> {
self.buf
}
/// Return the entire buffer concatenated into a single big Bytes
pub fn into_bytes(mut self) -> Bytes {
self.take_all()
}
/// Return the content as a stream of individual chunks
pub fn into_stream(self) -> ByteStream {
use futures::stream::StreamExt;
Box::pin(futures::stream::iter(self.buf).map(|x| Ok(x)))
}
}
impl Default for BytesBuf {