Thread overview
Base64 - Encoding and decoding
Nov 27, 2010
Nov 28, 2010
Nov 29, 2010
November 27, 2010
Hey guys,

I want encode and decode binary files like images, documents and similar file types to use it in an binary xml. For those I created a
simple command line tool which encode or decode an file.

The encoding of files will be processed by these lines:

ubyte[] buffer;
buffer.length = source.available();;

string content;

for (uint i = 0; i < buffer.length; i++) {
content ~= to!(char)(buffer[i]);


This seems to work correctly, but when I want decode the file, I always get "std.base64.Base64CharException: Invalid base64 character".
I'm currently using the following to decode the file:

char[] content;

for (uint i = 0; i < source.available(); i++) {
content ~= source.getc();


But... when I directly decode the encoded (without read the encoded content from external file), the decoded file is valid.

I hope anyone know where's my mistake :)

November 28, 2010
Nrgyzer Wrote:

> decode(to!(string)(content));
check out, what you send to decode function.

the code... /3_=
November 29, 2010
I solved the problem by replacing destination.write() to
destination.writeString() in the encoding function.

But... thanks for providing help :)