Function in io compiler

write_from

fn write_from(Stream s, Vec<byte> buf, int offset) -> Result<int, IoError>
Import
use io::{write_from};
Source: compiler/src/builtin_docs/io.hy

Writes buf[offset..] to s without waiting and returns how many bytes were written.

Like write, but starts at offset without copying the rest of the buffer, which suits a loop that resumes after a partial write. offset == buf.len() writes nothing and returns Ok(0); a negative offset or one past the end returns Err(IoError::InvalidInput).

Parameters#

NameType
sStream
bufVec<byte>
offsetint

Returns#

Result<int, IoError>

Examples#

use io::{stdout, write_from};
use string::{to_bytes};
use tests::assert;
let buf = to_bytes("skip: shown\n");
let n = match write_from(stdout(), buf, 6) {
    Result::Ok(n) => n,
    Result::Err(_) => 0,
};
assert!(n == 6);

See also#

  • io::write
  • 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