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