aboutsummaryrefslogtreecommitdiff
path: root/src/net/stream.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-02-23 11:46:57 +0100
committerAlex Auvolat <alex@adnab.me>2024-02-23 11:46:57 +0100
commit9b41f4ff2016b099ee706747828f5828f8c96b1c (patch)
tree3c9e06d8d0ca7162e97e765bbe8091a5eaf676fd /src/net/stream.rs
parent93552b9275a6a83653353e27c0ee0c64c7a23d59 (diff)
downloadgarage-9b41f4ff2016b099ee706747828f5828f8c96b1c.tar.gz
garage-9b41f4ff2016b099ee706747828f5828f8c96b1c.zip
[refactor-block] move read_stream_to_end to garage_net
Diffstat (limited to 'src/net/stream.rs')
-rw-r--r--src/net/stream.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/net/stream.rs b/src/net/stream.rs
index 88c3fed4..3ac6896d 100644
--- a/src/net/stream.rs
+++ b/src/net/stream.rs
@@ -200,3 +200,14 @@ pub fn asyncread_stream<R: AsyncRead + Send + Sync + 'static>(reader: R) -> Byte
pub fn stream_asyncread(stream: ByteStream) -> impl AsyncRead + Send + Sync + 'static {
tokio_util::io::StreamReader::new(stream)
}
+
+/// Reads all of the content of a `ByteStream` into a BytesBuf
+/// that contains everything
+pub async fn read_stream_to_end(mut stream: ByteStream) -> Result<BytesBuf, std::io::Error> {
+ let mut buf = BytesBuf::new();
+ while let Some(part) = stream.next().await {
+ buf.extend(part?);
+ }
+
+ Ok(buf)
+}