Composing a Base64 encoded file

2 views
Skip to first unread message

James Bishop

unread,
Oct 4, 2004, 4:28:05 AM10/4/04
to crypto...@eskimo.com
Good morning,

Can anybody describe an elegant way to create a base-64 encoded file
with a header and trailer like:

-------------------- BEGIN B64 OBJECT ----------------
My base64 encoded data
--------------------- END B64 OBJECT -----------------

I've setup the header and trailer as strings, so I can pipeline a
StringSource to a FileSink; but successive calls like:

StringSource(headerStr... FileSink(my output file));
StringSource(dataBuffer, new Base64Encoder(FileSink(my output file));
StringSource(trailerStr... FileSink(my output file));

just overwrite the data written to the output file.

What construct should I be using? A MessageQueue? A ChannelSwitch?

All the best
--


_____________________________________________
James Bishop
Institute for the Protection and Security of the Citizen (IPSC)
European Commission - Joint Research Centre
I - 21020 Ispra, Italy
Tel.: +39 0332 786225
Fax.: +39 0332 786280
e-mail: james....@jrc.it

Russell Robinson

unread,
Oct 4, 2004, 5:16:40 AM10/4/04
to James Bishop
Hi James,

James> I've setup the header and trailer as strings, so I can pipeline a
James> StringSource to a FileSink; but successive calls like:

James> StringSource(headerStr... FileSink(my output file));
James> StringSource(dataBuffer, new Base64Encoder(FileSink(my output file));
James> StringSource(trailerStr... FileSink(my output file));

James> just overwrite the data written to the output file.

I generally append it all to a string using a string sink that I
define like this:
typedef CryptoPP::StringSinkTemplate<STLString> STLStringSink;

and then output the resulting string to the file.

However, you can almost certainly do this:

ofstream f_out("filename");

StringSource(headerStr,...,new FileSink(f_out));
StringSource(dataBuffer,...,new FileSink(f_out));
StringSource(trailerStr,...,new FileSink(f_out));

HTH.

--
Russell Robinson (mailto:russro...@tectite.com)
Author of Tectite (CRM and Licensing for Software Developers)
Download your free CRM from: http://www.tectite.com/


Reply all
Reply to author
Forward
0 new messages