MCPcopy Create free account
hub / github.com/bytecodealliance/wstd / copy_to

Method copy_to

src/io/streams.rs:79–92  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 2

sendMethod · 0.80
copyFunction · 0.80

Calls 1

readyMethod · 0.45

Tested by

no test coverage detected