Search results

There are no results.

std.io.Read

Read

A type data can be read from (e.g. a File).

Required methods

read

Show source code
Hide source code
fn pub mut read(into: mut ByteArray, size: Int) -> Result[Int, Error]
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.

Default methods

read_all

Show source code
Hide 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.

Implementations

std.fs.file.

ReadOnlyFile

impl Read for ReadOnlyFile
std.fs.file.

ReadWriteFile

impl Read for ReadWriteFile
std.io.

Buffer

impl Read for Buffer
std.io.

BufferedReader

impl Read for BufferedReader
std.net.socket.

Socket

impl Read for Socket
std.net.socket.

TcpClient

impl Read for TcpClient
std.net.socket.

UdpSocket

impl Read for UdpSocket
std.net.socket.

UnixClient

impl Read for UnixClient
std.net.socket.

UnixDatagram

impl Read for UnixDatagram
std.net.socket.

UnixSocket

impl Read for UnixSocket
std.stdio.

STDIN

impl Read for STDIN
std.sys.

Stderr

impl Read for Stderr
std.sys.

Stdout

impl Read for Stdout