std.stdio.STDIN
class pub STDIN
The standard input stream of the current OS process.
Static methods
new
Show source codeHide source code
fn pub static new -> STDIN {
STDIN()
}
fn pub static new -> STDIN
Returns a new handle to the input stream.
Instance methods
read
Show source codeHide source code
fn pub mut read(into: mut ByteArray, size: Int) -> Result[Int, Error] {
match inko_stdin_read(_INKO.process, into, size) {
case { @tag = 0, @value = v } -> Result.Ok(v)
case { @tag = _, @value = e } -> Result.Error(Error.from_os_error(e))
}
}
fn pub mut read(into: mut ByteArray, size: Int) -> Result[Int, Error]
Reads bytes from a stream into a ByteArray
.
The return value is the number of bytes read.
The size
argument specifies how many bytes are to be read. The actual
number of bytes read may be less than this value.
read_all
Show source codeHide source code
fn pub mut read_all(bytes: mut ByteArray) -> Result[Int, Error] {
let mut total = 0
let mut read_size = INITIAL_READ_ALL_SIZE
loop {
let bytes_read = try read(into: bytes, size: read_size)
if bytes_read == 0 { return Result.Ok(total) }
total += bytes_read
# To reduce the overhead of large buffer reads, we increase the buffer
# size as more data is read.
if read_size < MAX_READ_ALL_SIZE { read_size *= 2 }
}
}
fn pub mut read_all(bytes: mut ByteArray) -> Result[Int, Error]
Reads all bytes from the stream into the ByteArray
.
If an error is encountered while reading, this method stops reading any more bytes and re-throws the error.
The return value is the number of bytes read.
Implemented traits
Read
impl Read for STDIN