diff options
author | Alex <alex@adnab.me> | 2024-02-23 15:49:43 +0000 |
---|---|---|
committer | Alex <alex@adnab.me> | 2024-02-23 15:49:43 +0000 |
commit | 61758ce0f91b930542bd2ee3c72735000cc12e75 (patch) | |
tree | 0a8c9c8d57abfa084188873dab2987ecfe93c0d7 /src/net/stream.rs | |
parent | 74d0c47f21ae2f9998a7dcbca3a27e3cc51e70b6 (diff) | |
parent | 6ee691e65f2c6f7b337a62cbfacaddb9ba9cd61a (diff) | |
download | garage-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/stream.rs')
-rw-r--r-- | src/net/stream.rs | 11 |
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) +} |