About
The io package in the Mys programming language.
API
io
trait Reader:
func read(self, size: i64) -> bytes:
Read given number of bytes. Always returns size number of bytes,
unless the connection was closed, in which case the remaining
data is returned.
func read_into(self, data: bytes, start: i64, size: i64) -> i64:
Read given number of bytes into given buffer. Always returns size
number of bytes, unless the connection was closed, in which
case the number of read bytes is returned.
func try_read_into(self, data: bytes, start: i64, size: i64) -> i64:
Try to read given number of bytes into given buffer. Returns number
of read bytes, which is at least one and at most given size
bytes, unless the connection was closed, in which case the
number of read bytes is returned.
trait Writer:
func write(self, data: bytes) -> i64:
Write given data. Returns number of bytes written, or zero if
the connection was closed.
func write_from(self, data: bytes, start: i64, size: i64) -> i64:
Write from given buffer. Returns number of bytes written, or zero
if the connection was closed.
io.buffered_reader
class BufferedReader(Reader):
Efficient reading of any amount of bytes. Small reads are using an
internal buffer for fewer calls to the underlying reader, while
big reads are read directly into given destination buffer.
func __init__(self, reader: Reader, size: i64 = 64):
Create a buffered reader that reads from given reader. Size is the
size of the internal buffer.
func clear(self):
Clear the buffer.
func read(self, size: i64) -> bytes:
Read given number of bytes. Always returns size number of bytes,
unless the connection was closed, in which case the remaining
number of bytes is returned.
func read_until(self, pattern: bytes, keep_pattern: bool = True) -> bytes?:
Read until given pattern is found. Returns None if the pattern was
not found before the reader was closed.
io.buffered_writer
class BufferedWriter(Writer):
Efficient writing of any amount of bytes. Small writes are using an
internal buffer for fewer calls to the underlying writer, while
big writes are written directly.
func __init__(self, writer: Writer, size: i64 = 64):
Create a buffered writer that writes to given writer. Size is the
size of the internal buffer.
func write(self, data: bytes) -> i64:
Write given data. Never blocks.
func flush(self):
Write all buffered data to the underlying writer.