Base64Impl.encode

Encode source into a char[] buffer using Base64 encoding.

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

Parameters

source R1

The input range to encode.

buffer R2

The char[] buffer to store the encoded result.

Return Value

Type: char[]

The slice of buffer that contains the encoded string.

Examples

ubyte[6] data = [0x83, 0xd7, 0x30, 0x7a, 0x01, 0x3f];
char[32] buffer;    // much bigger than necessary

// Just to be sure...
auto encodedLength = Base64.encodeLength(data.length);
assert(buffer.length >= encodedLength);

// encode() returns a slice to the provided buffer.
auto encoded = Base64.encode(data[], buffer[]);
assert(encoded is buffer[0 .. encodedLength]);
assert(encoded == "g9cwegE/");

Meta