Base64Impl.encode

Encodes source into an output range using Base64 encoding.

  1. char[] encode(R1 source, R2 buffer)
  2. char[] encode(R1 source, R2 buffer)
  3. size_t encode(const(E)[] source, R range)
    template Base64Impl(char Map62th, char Map63th, char Padding = '=')
    size_t
    encode
    (
    E
    R
    )
    (
    scope const(E)[] source
    ,
    auto ref R range
    )
    if (
    is(E : ubyte) &&
    isOutputRange!(R, char)
    &&
    !is(R == char[])
    )
    out (result) { assert (result == encodeLength(source.length), "The number of put is different from the length of Base64"); }
  4. size_t encode(R1 source, R2 range)
  5. char[] encode(Range source)
  6. char[] encode(Range source)

Parameters

source const(E)[]

The input range to encode.

range R

The output range to store the encoded result.

Return Value

Type: size_t

The number of times the output range's put method was invoked.

Examples

import std.array : appender;

auto output = appender!string();
ubyte[] data = [0x1a, 0x2b, 0x3c, 0x4d, 0x5d, 0x6e];

// This overload of encode() returns the number of calls to the output
// range's put method.
assert(Base64.encode(data, output) == 8);
assert(output.data == "Gis8TV1u");

Meta