|
Boost : |
Subject: [boost] Is Boost interested in the Boost-based Base64 library
From: Denis Shevchenko (for.dshevchenko_at_[hidden])
Date: 2011-06-09 14:43:38
Hi all!
Not so long ago I was looking for a solution to Base64 encoding/decoding.
In this page -
http://www.boost.org/doc/libs/1_46_1/libs/serialization/doc/dataflow.html
- I found example of such solution, with 'base64_from_binary' and
'transform_width' iteartors. But it is just a "blank", not ready-to-use
solution.
I created solution. But I definitely know many developers looking for a
simple, ready-to-use, header-only and 'real C++' solution for Base64. So I
want to offer you such solution.
Some examples:
int main() {
std::string my_text = "My text for encoding!";
std::string encoded_text = boost::base64().encode( my_text );
std::string my_text_again = boost::base64().decode< std::string >(
encoded );
}
For binary data:
int main() {
typedef std::vector< unsigned char > binary_string;
binary_string my_bin = list_of( 0xFF )( 0xAA )( 0x01 );
std::string encoded_bin = boost::base64().encode( my_bin );
binary_string my_bin_again = boost::base64().decode< binary_string >(
encoded );
}
For streams:
int main() {
boost::filesystem::ifstream my_jpeg( "/some/path/to/my/image" );
// fstream checking omitted...
std::string encoded_jpeg = boost::base64().encode( my_jpeg );
boost::filesystem::ofstream my_jpeg_again(
"/some/path/to/decoded/image" );
// fstream checking omitted...
boost::base64().decode( encoded_jpeg, my_jpeg_again );
}
This is first variant. IMHO such solution will be useful for Boost users.
What you think about it?
- Denis
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk