BufferedReader structv0.1.0
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.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
source | Reader | where the bytes come from |
capacity | uint | how many bytes the buffer holds |
Returns: the buffered stream; Other when the allocator refused the buffer
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
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
Consume
pub func Consume(self: &var BufferedReader, count: uint)
Marks count buffered bytes as read.
| Name | Type | Description |
|---|---|---|
count | uint | how many bytes to consume |
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
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.
| Name | Type | Description |
|---|---|---|
into | var char8[..] | receives the bytes |
Returns: how many bytes were read; IsEnd at the end of input
Release
pub func Release(self: &var BufferedReader)
Gives the buffer back.
Destructor
func ~BufferedReader(self: &var BufferedReader)
Gives the buffer back. Unread buffered bytes are abandoned, which loses nothing anybody asked for.
Related
DefaultBufferCapacity
pub const DefaultBufferCapacity: uint = 8192;
The room a buffered stream takes when the caller expresses no preference.