MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / write

Method write

crates/wasi/src/p1.rs:291–317  ·  view source on GitHub ↗
(
        &self,
        memory: &mut GuestMemory<'_>,
        host: &mut impl streams::HostOutputStream,
        output_stream: Resource<streams::OutputStream>,
        bytes: GuestPtr<[u8]>,
    )

Source from the content-addressed store, hash-verified

289 }
290 }
291 async fn write(
292 &self,
293 memory: &mut GuestMemory<'_>,
294 host: &mut impl streams::HostOutputStream,
295 output_stream: Resource<streams::OutputStream>,
296 bytes: GuestPtr<[u8]>,
297 ) -> StreamResult<usize> {
298 use streams::HostOutputStream as Streams;
299
300 let bytes = memory
301 .as_cow(bytes)
302 .map_err(|e| StreamError::Trap(e.into()))?;
303 let mut bytes = &bytes[..];
304
305 let total = bytes.len();
306 while !bytes.is_empty() {
307 // NOTE: blocking_write_and_flush takes at most one 4k buffer.
308 let len = bytes.len().min(4096);
309 let (chunk, rest) = bytes.split_at(len);
310 bytes = rest;
311
312 Streams::blocking_write_and_flush(host, output_stream.borrowed(), Vec::from(chunk))
313 .await?
314 }
315
316 Ok(total)
317 }
318}
319
320#[derive(Debug)]

Callers 8

fd_write_implMethod · 0.45
write_byteFunction · 0.45
args_getMethod · 0.45
environ_getMethod · 0.45
poll_oneoffMethod · 0.45
open_atMethod · 0.45
poll_oneoffMethod · 0.45
blocking_write_and_flushFunction · 0.45

Calls 9

blocking_write_and_flushFunction · 0.85
fromFunction · 0.85
OkFunction · 0.85
as_cowMethod · 0.80
borrowedMethod · 0.80
TrapClass · 0.50
lenMethod · 0.45
is_emptyMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected