diff options
author | Alex Auvolat <alex@adnab.me> | 2024-02-23 16:50:34 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2024-02-23 16:50:34 +0100 |
commit | 916c67ccf4c9d31c14088f2d775e15c64750458f (patch) | |
tree | 63226f78b128f33b63d3b223283047372bcc31f2 /src/net/stream.rs | |
parent | 81cebdd12415381f67747e96591e83b1a4a8cc0b (diff) | |
parent | 61758ce0f91b930542bd2ee3c72735000cc12e75 (diff) | |
download | garage-916c67ccf4c9d31c14088f2d775e15c64750458f.tar.gz garage-916c67ccf4c9d31c14088f2d775e15c64750458f.zip |
Merge branch 'main' into next-0.10
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) +} |