Function in io compiler

write

fn write(Stream s, Vec<byte> buf) -> Result<int, IoError>
Import
use io::{write};
Source: 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#

NameType
sStream
bufVec<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_all
  • stdin: 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 matching capture_end().
  • capture_end: Ends the innermost capture_begin() and returns what it kept, as (stdout, stderr).
  • open: Opens the file at path with mode and returns a stream on it.
  • close: Closes s.
↑ ↓ navigate ↵ open