Move the entire contents of an input stream directly into an output stream, until the input stream has closed. This operation is optimized to avoid copying stream contents into and out of memory.
(&self, writer: &AsyncOutputStream)
| 77 | /// stream, until the input stream has closed. This operation is optimized |
| 78 | /// to avoid copying stream contents into and out of memory. |
| 79 | pub async fn copy_to(&self, writer: &AsyncOutputStream) -> std::io::Result<u64> { |
| 80 | let mut written = 0; |
| 81 | loop { |
| 82 | self.ready().await; |
| 83 | writer.ready().await; |
| 84 | match writer.stream.splice(&self.stream, u64::MAX) { |
| 85 | Ok(n) => written += n, |
| 86 | Err(StreamError::Closed) => break Ok(written), |
| 87 | Err(StreamError::LastOperationFailed(err)) => { |
| 88 | break Err(std::io::Error::other(err.to_debug_string())); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /// Use this `AsyncInputStream` as a `futures_lite::stream::Stream` with |
| 95 | /// items of `Result<Vec<u8>, std::io::Error>`. The returned byte vectors |