Io::Stream - mfichman/jogo GitHub Wiki

This object is used to perform buffered character I/O on a file. It can be used to read from any device or input that the OS supports for the underlying handle type, including sockets, files, pipes, etc.

@init(desc Int, type Io::StreamType)

Initializes a new stream, with 'handle' being an opaque pointer to the OS file descriptor. Note that if 'handle' is invalid, then subsequent reads and writes will fail, and 'err' will be set.

@destroy()

Closes the file if it is still open.

read(buffer Io::Buffer)

Reads data into 'buffer', and sets the 'count' field of buffer to the number of bytes read. This function will read up 'n' bytes, where 'n' is equal to the 'length' field of 'buffer'. If data is already buffered to the internal buffer, that data will be copied into 'buffer' first before an attempt to read more bytes from the OS is made. This function implements an unbuffered read; the bytes returned by the OS-level read call go directly into the buffer.

write(buffer Io::Buffer)

Writes the data in 'buffer', and blocks until all the bytes are written or the 'err' flag is set. If data is already buffered in the internal buffer, then 'flush()' will be called before writing 'buffer' to the output stream. This function implements an unbuffered write; the bytes will go directly to the OS-level write system call.

get() Char

Returns the next character in the input stream.

put(character Char)

Writes 'char' to the output buffer. The character is not guaranteed to be written to the output stream until 'flush()' is called.

scan(delim String) String

Reads all characters up to and including the first instance of 'char'. Returns a string containing the characters read.

print(string String)

Writes the characters in 'string' to the file. The string is not guaranteed to be written to the output stream until 'flush()' is called.

scanln() String

Reads in a line up to the ending '\n'

println(string String)

Prints a string followed by '\n', and flushes the output.

peek() Char

Reads a character, but does not remove it from the internal buffer. Call 'get' to read the next character and remove it.

flush()

Writes any characters in the internal output buffer to the output stream.

pipe(input Io::Stream)

Reads all bytes from 'input' and outputs to this stream.

close()

Calls 'flush()' then closes the file descriptor, so that no more characters may be read or written.

end()

Writes the EOF, if this is a socket stream. This closes the socket stream for writing, but does not close it for reading.

handle?() Int

No comment

status=(_arg0 Io::StreamStatus)

No comment

status?() Io::StreamStatus

No comment

mode=(_arg0 Io::StreamMode)

No comment

mode?() Io::StreamMode

No comment

type?() Io::StreamType

No comment

error?() Int

No comment