tango.util.encode.Base64

This module is used to decode and encode base64 char[] arrays.

Members

Functions

allocateEncodeSize
size_t allocateEncodeSize(const(ubyte[]) data)

calculates and returns the size needed to encode the length of the array passed.

allocateEncodeSize
size_t allocateEncodeSize(size_t length)

calculates and returns the size needed to encode the length passed.

decode
ubyte[] decode(const(char[]) data)

decodes an ASCCI base64 string and returns it as ubyte[] data. Pre-allocates the size of the array.

decode
ubyte[] decode(const(char[]) data, ubyte[] buff)

decodes an ASCCI base64 string and returns it as ubyte[] data.

encode
char[] encode(const(ubyte[]) data, char[] buff)

encodes data and returns as an ASCII base64 string.

encode
char[] encode(const(ubyte[]) data)

encodes data and returns as an ASCII base64 string.

encodeChunk
size_t encodeChunk(const(ubyte[]) data, char[] buff, size_t bytesEncoded)

encodes data into buff and returns the number of bytes encoded. this will not terminate and pad any "leftover" bytes, and will instead only encode up to the highest number of bytes divisible by three.

Examples

char[] blah = "Hello there, my name is Jeff.";
scope encodebuf = new char[allocateEncodeSize(cast(ubyte[])blah)];
char[] encoded = encode(cast(ubyte[])blah, encodebuf);

scope decodebuf = new ubyte[encoded.length];
if (cast(char[])decode(encoded, decodebuf) == "Hello there, my name is Jeff.")
    Stdout("yay").newline;

Meta