decode

Decodes an ASCII base64 string and returns it as ubyte[] data. Allocates the size of the array.

This decoder will ignore non-base64 characters, so for example data with newline in it is valid. Note that the entries in the provided decode table are not required to be unique. This allows the use of decode tables with alternatives for certain characters.

Since the padding is required only between multiple base64 strings (for the decoder not to interpret the start of the next string as the end of the previous one), data may or may not contain the trailing padding, and it will still be decoded correctly.

Note: With explicit padding, three padding bytes will cause decoder to throw an Exception. However, in the case of implicit padding, the last byte will be silently ignored if it contains less than two bytes. This was the undocumented behaviour of the decoder, and it will be changed in the next major version.

Parameters

Table

The decode table to use. Variadic template parameter is used to allow passing it as an expression in D1, but a single ubyte[256] is expected.

data cstring

what is to be decoded

Examples

mstring myDecodedString = cast(mstring)decode("SGVsbG8sIGhvdyBhcmUgeW91IHRvZGF5Pw==");
Stdout(myDecodedString).newline; // Hello, how are you today?

Meta