BufferedReader structv0.1.0

Source
A reader that fills a buffer in large reads and serves small ones from it.
pub struct BufferedReader {
    // private fields
}

Move-only: it owns its buffer. The reader it wraps is borrowed through the interface value and must outlive it.

Associated functions

New

pub func New(
    allocator: Allocator,
    source: Reader,
    capacity: uint
) -> BufferedReader ! IoError

A buffered reader over source with capacity bytes of buffer.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
sourceReaderwhere the bytes come from
capacityuinthow many bytes the buffer holds

Returns: the buffered stream; Other when the allocator refused the buffer

Source

Methods

Available

pub func Available(self: &BufferedReader) -> uint

How many buffered bytes wait unread.

Returns: how many bytes are already buffered and can be taken without a read

Source

Buffered

pub func Buffered(self: &BufferedReader) -> char8[..]

The unread bytes, borrowed, without consuming them. What line reading is built from: look, decide, then Consume what was used.

Returns: the buffered bytes, borrowed and valid until the next fill

Source

Consume

pub func Consume(self: &var BufferedReader, count: uint)

Marks count buffered bytes as read.

NameTypeDescription
countuinthow many bytes to consume

Source

Fill

pub func Fill(self: &var BufferedReader) -> ! IoError

Refills an empty buffer from the source, retrying interruptions. Reports what the source reported; EndOfStream when the source is done. A source that reports success while handing over nothing breaks the Reader contract, and is reported as the end rather than looped on.

Returns: success when at least one byte is buffered; IsEnd at the end of the source

Source

Read

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

Fills what it can of into: from the buffer while it has bytes, straight from the source for a request already larger than the whole buffer.

NameTypeDescription
intovar char8[..]receives the bytes

Returns: how many bytes were read; IsEnd at the end of input

Source

Release

pub func Release(self: &var BufferedReader)

Gives the buffer back.

Source

Destructor

func ~BufferedReader(self: &var BufferedReader)

Gives the buffer back. Unread buffered bytes are abandoned, which loses nothing anybody asked for.

Source

DefaultBufferCapacity

pub const DefaultBufferCapacity: uint = 8192;

The room a buffered stream takes when the caller expresses no preference.

Source