Streams v0.1.0
StreamCodec
pub variant StreamCodec {
Hex(HexCase),
Base64(Base64Variant),
Base32(Base32Variant)
}
Which encoding a stream uses, with the form of it. Copy.
Cases
| Name | Description |
|---|---|
Hex(HexCase) | Hexadecimal, two characters per byte. |
Base64(Base64Variant) | Base64, four characters per three bytes. |
Base32(Base32Variant) | Base32, eight characters per five bytes. |
EncodingWriter
pub struct EncodingWriter {
// private fields
}
A writer that encodes what is written to it onto another writer. Not copied.
The text is complete only once Finish has written the last group and its padding.
Associated functions
New
pub func New(
sink: Writer,
codec: StreamCodec
) -> EncodingWriter
A writer encoding with codec onto sink.
| Name | Type | Description |
|---|---|---|
sink | Writer | where the text goes |
codec | StreamCodec | the encoding and its form |
Returns: the writer
Methods
Finish
pub func Finish(self: &var EncodingWriter) -> ! IoError
Ends the text: encodes the bytes of an incomplete last group, with padding where the form uses it, and flushes the writer underneath. Nothing more may be written afterwards.
Returns: nothing, or why the writer underneath failed
Implements Writer
EncodingWriter conforms to Writer.
Write
pub func Write(
self: &var EncodingWriter,
bytes: char8[..]
) -> uint ! IoError
Encodes bytes, writing every complete group and holding back the rest of an incomplete one.
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the bytes to encode |
Returns: how many were taken, which is all of them, or fails with InvalidInput after Finish
Flush
pub func Flush(self: &var EncodingWriter) -> ! IoError
Flushes the writer underneath. An incomplete group stays held back, since its characters depend on bytes
not yet written; Finish is what writes it.
Returns: nothing, or why the writer underneath failed
DecodingReader
pub struct DecodingReader {
// private fields
}
A reader that decodes text from another reader into bytes. Not copied.
The text is held to the same rules as the slice decoders, so text that would not decode whole fails with
InvalidInput when the reader reaches it. Crockford Base32 skips its hyphens, as its specification asks.
Associated functions
New
pub func New(
source: Reader,
codec: StreamCodec
) -> DecodingReader
A reader decoding codec text from source.
| Name | Type | Description |
|---|---|---|
source | Reader | where the text comes from |
codec | StreamCodec | the encoding and its form |
Returns: the reader
Implements Reader
DecodingReader conforms to Reader.
Read
pub func Read(
self: &var DecodingReader,
into: var char8[..]
) -> uint ! IoError
Decodes into into as many bytes as are ready, reading more text when none are.
| Name | Type | Description |
|---|---|---|
into | var char8[..] | where the bytes go |
Returns: how many were decoded, or fails with EndOfStream after the last, or with InvalidInput for text
that is not in the form