D Programming Language 2.0

Last update Wed Aug 1 09:43:20 2012

# std.base64

Encoding / Decoding Base64 format.

Implemented according to RFC 4648 - The Base16.

Example:
Support Range interface using Encoder / Decoder.

Example:

License:
Boost License 1.0.

Authors:
Masahiro Nakagawa, Daniel Murphy (Single value Encoder and Decoder)

Source:
std/base64.d

alias Base64;
  The Base64

alias Base64URL;
  The "URL and Filename safe" Base64

template Base64Impl(char Map62th,char Map63th,char Padding = '=')
  Core implementation for Base64 format.

  Example:

       alias Base64Impl!('+', '/')                   Base64;    // The Base64 format(Already defined).
       alias Base64Impl!('!', '=', Base64.NoPadding) Base64Re;  // non-standard Base64 format for Regular expression

  NOTE:
  encoded-string doesn't have padding character if set Padding parameter to NoPadding.

  size_t encodeLength(in size_t sourceLength);
    Calculates the minimum length for encoding.

    Parameters:

    size_t sourceLength | the length of source array.

    Returns:
    the calculated length using sourceLength.

  char[] encode(R1, R2)(in R1 source, R2 buffer);
  char[] encode(R1, R2)(R1 source, R2 buffer);
    Encodes source into buffer.

    Parameters:

    source | an InputRange to encode.
    range | a buffer to store encoded result.

    Returns:
    the encoded string that slices buffer.

  size_t encode(R1, R2)(in R1 source, R2 range);
  size_t encode(R1, R2)(R1 source, R2 range);
    Encodes source into range.

    Parameters:

    source | an InputRange to encode.
    range | an OutputRange to put encoded result.

    Returns:
    the number of calling put.

  char[] encode(Range)(Range source);
  char[] encode(Range)(Range source);
    Encodes source to new buffer.

    Shortcut to encode(source, buffer) function.

  struct Encoder(Range) if (isInputRange!(Range) && (is(ElementType!(Range) : const(ubyte)[]) || is(ElementType!(Range) : const(char)[])));
    Range that encodes chunk data at a time.

    const bool empty();
      Range primitive operation that checks iteration state.

      Returns:
      true if there are no more elements to be iterated.

    char[] front();
      Range primitive operation that returns the currently iterated element.

      Returns:
      the encoded string.

    void popFront();
      Range primitive operation that advances the range to its next element.

      Throws:
      an Exception when you try to call popFront on empty range.

    typeof(this) save();
      Captures a Range state.

      Returns:
      a copy of this.

  struct Encoder(Range) if (isInputRange!(Range) && is(ElementType!(Range) : ubyte));
    Range that encodes single character at a time.

    const bool empty();
      Range primitive operation that checks iteration state.

      Returns:
      true if there are no more elements to be iterated.

    ubyte front();
      Range primitive operation that returns the currently iterated element.

      Returns:
      the encoded character.

    void popFront();
      Range primitive operation that advances the range to its next element.

      Throws:
      an Exception when you try to call popFront on empty range.

    typeof(this) save();
      Captures a Range state.

      Returns:
      a copy of this.

  Encoder!(Range) encoder(Range)(Range range);
    Iterates through an InputRange at a time by using Encoder.

    Default Encoder encodes chunk data.

    Example:

    In addition, You can use Encoder that returns encoded single character. This Encoder performs Range-based and lazy encoding.

    Example:

    Parameters:

    range | an InputRange to iterate.

    Returns:
    a Encoder object instantiated and initialized according to the arguments.

  size_t decodeLength(in size_t sourceLength);
    Calculates the minimum length for decoding.

    Parameters:

    size_t sourceLength | the length of source array.

    Returns:
    calculated length using sourceLength.

  ubyte[] decode(R1, R2)(in R1 source, R2 buffer);
  ubyte[] decode(R1, R2)(R1 source, R2 buffer);
    Decodes source into buffer.

    Parameters:

    source | an InputRange to decode.
    buffer | a buffer to store decoded result.

    Returns:
    the decoded string that slices buffer.

    Throws:
    an Exception if source has character outside base-alphabet.

  size_t decode(R1, R2)(in R1 source, R2 range);
  size_t decode(R1, R2)(R1 source, R2 range);
    Decodes source into range.

    Parameters:

    source | an InputRange to decode.
    range | an OutputRange to put decoded result

    Returns:
    the number of calling put.

    Throws:
    an Exception if source has character outside base-alphabet.

  ubyte[] decode(Range)(Range source);
  ubyte[] decode(Range)(Range source);
    Decodes source into new buffer.

    Shortcut to decode(source, buffer) function.

  struct Decoder(Range) if (isInputRange!(Range) && (is(ElementType!(Range) : const(char)[]) || is(ElementType!(Range) : const(ubyte)[])));
    Range that decodes chunk data at a time.

    const bool empty();
      Range primitive operation that checks iteration state.

      Returns:
      true if there are no more elements to be iterated.

    ubyte[] front();
      Range primitive operation that returns the currently iterated element.

      Returns:
      the decoded result.

    void popFront();
      Range primitive operation that advances the range to its next element.

      Throws:
      an Exception when you try to call popFront on empty range.

    typeof(this) save();
      Captures a Range state.

      Returns:
      a copy of this.

  struct Decoder(Range) if (isInputRange!(Range) && is(ElementType!(Range) : char));
    Range that decodes single character at a time.

    const bool empty();
      Range primitive operation that checks iteration state.

      Returns:
      true if there are no more elements to be iterated.

    ubyte front();
      Range primitive operation that returns the currently iterated element.

      Returns:
      the decoded result.

    void popFront();
      Range primitive operation that advances the range to its next element.

      Throws:
      an Exception when you try to call popFront on empty range.

    typeof(this) save();
      Captures a Range state.

      Returns:
      a copy of this.

  Decoder!(Range) decoder(Range)(Range range);
    Iterates through an InputRange at a time by using Decoder.

    Default Decoder decodes chunk data.

    Example:

    In addition, You can use Decoder that returns decoded single character. This Decoder performs Range-based and lazy decoding.

    Example:

    NOTE:
    If you use ByChunk, chunk-size should be the multiple of 4. Decoder can't judge a encode-boundary.

    Parameters:

    range | an InputRange to iterate.

    Returns:
    a Decoder object instantiated and initialized according to the arguments.

Masahiro Nakagawa 2010-. | Page generated by Ddoc.