aboutsummaryrefslogtreecommitdiff
path: root/src/net/bytes_buf.rs
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2024-02-23 15:49:43 +0000
committerAlex <alex@adnab.me>2024-02-23 15:49:43 +0000
commit61758ce0f91b930542bd2ee3c72735000cc12e75 (patch)
tree0a8c9c8d57abfa084188873dab2987ecfe93c0d7 /src/net/bytes_buf.rs
parent74d0c47f21ae2f9998a7dcbca3a27e3cc51e70b6 (diff)
parent6ee691e65f2c6f7b337a62cbfacaddb9ba9cd61a (diff)
downloadgarage-61758ce0f91b930542bd2ee3c72735000cc12e75.tar.gz
garage-61758ce0f91b930542bd2ee3c72735000cc12e75.zip
Merge pull request 'some refactoring on data read/write path' (#729) from refactor-block into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/729
Diffstat (limited to 'src/net/bytes_buf.rs')
-rw-r--r--src/net/bytes_buf.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/net/bytes_buf.rs b/src/net/bytes_buf.rs
index 3929a860..1d928ffb 100644
--- a/src/net/bytes_buf.rs
+++ b/src/net/bytes_buf.rs
@@ -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 {