The OpenD Programming Language

Base64Impl.decoder

Construct a Decoder that iterates over the decoding of the given Base64 encoded data.

  1. Decoder!(Range) decoder(Range range)
  2. Decoder!(const(ubyte)[]) decoder(const(char)[] range)
    template Base64Impl(char Map62th, char Map63th, char Padding = '=')
    Decoder!(const(ubyte)[])
    decoder
    ()
    (
    const(char)[] range
    )

Parameters

range const(char)[]

An input range over the data to be decoded, or a char array. Will not accept wchar[] nor dchar[].

Return Value

Type: Decoder!(const(ubyte)[])

If range is a range or array of char, a Decoder that iterates over the bytes of the corresponding Base64 decoding.

If range is a range of ranges of characters, a Decoder that iterates over the decoded strings corresponding to each element of the range.

In both cases, the returned Decoder will be a forward range if the given range is at least a forward range, otherwise it will be only an input range.

If the input data contains characters not found in the base alphabet of the current Base64 encoding scheme, the returned range may throw a Base64Exception.

Examples

This example shows decoding over a range of input data lines.

foreach (decoded; Base64.decoder(stdin.byLine()))
{
    writeln(decoded);
}

This example shows decoding one byte at a time.

auto encoded = Base64.encoder(cast(ubyte[])"0123456789");
foreach (n; map!q{a - '0'}(Base64.decoder(encoded)))
{
    writeln(n);
}
import std.algorithm.comparison : equal;
string encoded =
    "VGhvdSBzaGFsdCBuZXZlciBjb250aW51ZSBhZnRlciBhc3NlcnRpbmcgbnVsbA==";

assert(Base64.decoder(encoded)
    .equal("Thou shalt never continue after asserting null"));

Meta