write
fn write(Stream s, Vec<byte> buf) -> Result<int, IoError> Import
Source: use io::{write}; compiler/src/builtin_docs/io.hy Writes bytes from buf to s without waiting and returns how many were written.
The count may be less than buf.len() when the OS accepts only part of
it, and Err(IoError::WouldBlock) means nothing could be written yet;
call wait_writable(s) and retry. io::sync::write_all loops until
everything is written. Writing to a closed stream returns
Err(IoError::AlreadyClosed).
Parameters#
| Name | Type |
|---|---|
s | Stream |
buf | Vec<byte> |
Returns#
Result<int, IoError>
Examples#
use io::{stdout, write};
use string::{to_bytes};
use tests::assert;
let n = match write(stdout(), to_bytes("hi\n")) {
Result::Ok(n) => n,
Result::Err(_) => 0,
};
assert!(n == 3);
See also#
io::sync::write_allstdin: Returns a new stream on the process’s standard input.stdout: Returns a new stream on the process’s standard output.stderr: Returns a new stream on the process’s standard error.capture_begin: Starts keeping this thread’s stdout and stderr writes in memory instead of writing them, until the matchingcapture_end().capture_end: Ends the innermostcapture_begin()and returns what it kept, as(stdout, stderr).open: Opens the file atpathwithmodeand returns a stream on it.close: Closess.