v0.4.0

Reader interfacev0.1.0

Source
Somewhere bytes come from.
pub interface Reader {
    func Read(
        &var self,
        into: var char8[..]
    ) -> uint throws IoError;
}

Requirements

Read

func Read(
    &var self,
    into: var char8[..]
) -> uint throws IoError

Fills what it can of into and succeeds with how much. An implementation reports the end of the stream as the EndOfStream failure. Every reading helper in this package also takes a success of zero for a non-empty buffer as the end, never as a reason to ask again, so a reader that ends that way is not looped on. A non-blocking stream with nothing ready fails with WouldBlock.

NameTypeDescription
intovar char8[..]receives the bytes

Returns: how many bytes were read, which may be fewer than into holds; IsEnd at the end of the stream

Source

Implementations

TypeSummary
ByteReaderA reader of a slice of bytes, from its start.
StandardInStandard input, with the console-versus-redirection question answered at acquisition.

ZeroProgressLimit

pub const ZeroProgressLimit: uint = 3;

How many consecutive zero-progress rounds WriteAll tolerates before refusing. An interruption is retried without counting; this counts only rounds where the stream reported success and moved nothing, which is a stream that will never finish the job.

Source

ReadExact

pub func ReadExact(
    reader: &var Reader,
    into: var char8[..]
) throws IoError

Fills all of into, looping over partial reads, or says why it could not. Interruptions are retried at once. The end of the stream, reported as EndOfStream or as a read of zero bytes, is EndOfStream when it comes before the first byte, so a caller reading records stops cleanly between them, and UnexpectedEnd once part of into has been written. Any other failure, WouldBlock included, is returned as itself. After a failure into may be partly written and how much is not reported: a caller who needs the count, as one reading a non-blocking stream does, reads incrementally with Read.

Source

Parameters

NameTypeDescription
reader&var Readerwhere the bytes come from
intovar char8[..]receives the bytes

Returns: success only when into was filled; IsEnd if the stream ended first, UnexpectedEnd if partway