std.io.Read
Read
A type data can be read from (e.g. a File).
Required methods
read
Show source codeHide 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 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.
Implementations
ReadOnlyFile
impl Read for ReadOnlyFile
ReadWriteFile
impl Read for ReadWriteFile
Buffer
impl Read for Buffer
BufferedReader
impl Read for BufferedReader
Socket
impl Read for Socket
TcpClient
impl Read for TcpClient
UdpSocket
impl Read for UdpSocket
UnixClient
impl Read for UnixClient
UnixDatagram
impl Read for UnixDatagram
UnixSocket
impl Read for UnixSocket
STDIN
impl Read for STDIN
Stderr
impl Read for Stderr
Stdout
impl Read for Stdout