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.
Constructors
BufferedReader
pub func BufferedReader(
allocator: Allocator,
source: Reader,
capacity: uint
) -> BufferedReader throws 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) -> 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) -> 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(&var self, count: uint)
Marks count buffered bytes as read.
| Name | Type | Description |
|---|---|---|
count | uint | how many bytes to consume |
Fill
pub func Fill(&var self) throws IoError
Refills an empty buffer from the source, retrying interruptions.
Reports what the source reported, WouldBlock included, and EndOfStream when the source is done. A source
that reports success while handing over nothing 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(
&var self,
into: var char8[..]
) -> uint throws 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.
Interruptions of the source are retried; any other failure, WouldBlock included, is returned as itself.
| 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(&var self)
Gives the buffer back.
Destructor
func ~BufferedReader(&var self)
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.