Streams v0.1.0

Source
Encoding and decoding through a writer or a reader, a block at a time.

StreamCodec

pub variant StreamCodec {
    Hex(HexCase),
    Base64(Base64Variant),
    Base32(Base32Variant)
}

Which encoding a stream uses, with the form of it. Copy.

Source

Cases

NameDescription
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.

Source

Associated functions

New

pub func New(
    sink: Writer,
    codec: StreamCodec
) -> EncodingWriter

A writer encoding with codec onto sink.

NameTypeDescription
sinkWriterwhere the text goes
codecStreamCodecthe encoding and its form

Returns: the writer

Source

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

Source

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.

NameTypeDescription
byteschar8[..]the bytes to encode

Returns: how many were taken, which is all of them, or fails with InvalidInput after Finish

Source

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

Source

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.

Source

Associated functions

New

pub func New(
    source: Reader,
    codec: StreamCodec
) -> DecodingReader

A reader decoding codec text from source.

NameTypeDescription
sourceReaderwhere the text comes from
codecStreamCodecthe encoding and its form

Returns: the reader

Source

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.

NameTypeDescription
intovar 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

Source