Base64Impl

Template for implementing Base64 encoding and decoding.

For most purposes, direct usage of this template is not necessary; instead, this module provides default implementations: Base64, implementing basic Base64 encoding, and Base64URL and Base64URLNoPadding, that implement the Base64 variant for use in URLs and filenames, with and without padding, respectively.

Customized Base64 encoding schemes can be implemented by instantiating this template with the appropriate arguments. For example:

// Non-standard Base64 format for embedding in regular expressions.
alias Base64Re = Base64Impl!('!', '=', Base64.NoPadding);

NOTE: Encoded strings will not have any padding if the Padding parameter is set to NoPadding.

Members

Functions

decode
ubyte[] decode(R1 source, R2 buffer)

Decodes source into the given buffer.

decode
size_t decode(R1 source, R2 range)

Decodes source into a given output range.

decode
ubyte[] decode(Range source)

Decodes source into newly-allocated buffer.

decodeLength
size_t decodeLength(size_t sourceLength)

Given a Base64 encoded string, calculates the length of the decoded string.

decoder
Decoder!(const(ubyte)[]) decoder(const(char)[] range)

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

decoder
Decoder!(Range) decoder(Range range)

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

encode
char[] encode(R1 source, R2 buffer)

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

encode
size_t encode(const(E)[] source, R range)
size_t encode(R1 source, R2 range)

Encodes source into an output range using Base64 encoding.

encode
char[] encode(Range source)

Encodes source to newly-allocated buffer.

encodeLength
size_t encodeLength(size_t sourceLength)

Calculates the length needed to store the encoded string corresponding to an input of the given length.

encoder
Encoder!(Range) encoder(Range range)

Construct an Encoder that iterates over the Base64 encoding of the given input range.

Manifest constants

NoPadding
enum NoPadding;

represents no-padding encoding

Structs

Decoder
struct Decoder(Range)

An input range that iterates over the decoded data of a range of Base64 encodings.

Decoder
struct Decoder(Range)

An input range that iterates over the bytes of data decoded from a Base64 encoded string.

Encoder
struct Encoder(Range)

An input range that iterates over the respective Base64 encodings of a range of data items.

Encoder
struct Encoder(Range)

An input range that iterates over the encoded bytes of the given source data.

Examples

import std.string : representation;

// pre-defined: alias Base64 = Base64Impl!('+', '/');
ubyte[] emptyArr;
assert(Base64.encode(emptyArr) == "");
assert(Base64.encode("f".representation) == "Zg==");
assert(Base64.encode("foo".representation) == "Zm9v");

alias Base64Re = Base64Impl!('!', '=', Base64.NoPadding);
assert(Base64Re.encode("f".representation) == "Zg");
assert(Base64Re.encode("foo".representation) == "Zm9v");

Meta