Boost C++ Libraries: Ticket #5630: base64 encode/decode for std::istreambuf_iterator/std::ostreambuf_iterator https://svn.boost.org/trac10/ticket/5630 <p> MSVS 2008 The code: </p> <pre class="wiki">#include "boost/archive/iterators/base64_from_binary.hpp" #include "boost/archive/iterators/binary_from_base64.hpp" #include "boost/archive/iterators/transform_width.hpp" //typedefs typedef std::istreambuf_iterator&lt;char&gt; my_istream_iterator; typedef std::ostreambuf_iterator&lt;char&gt; my_ostream_iterator; typedef boost::archive::iterators::base64_from_binary&lt; boost::archive::iterators::transform_width&lt; my_istream_iterator, 6, 8&gt; &gt; bin_to_base64; typedef boost::archive::iterators::transform_width&lt; boost::archive::iterators::binary_from_base64&lt; my_istream_iterator &gt;, 8, 6 &gt; base64_to_bin; void test() { { //INPUT FILE!!! std::ifstream ifs("test.zip", std::ios_base::in|std::ios_base::binary); std::ofstream ofs("test.arc", std::ios_base::out|std::ios_base::binary); std::copy( bin_to_base64( my_istream_iterator(ifs &gt;&gt; std::noskipws) ), bin_to_base64( my_istream_iterator() ), my_ostream_iterator(ofs) ); } { std::ifstream ifs("test.arc", std::ios_base::in|std::ios_base::binary); std::ofstream ofs("test.rez", std::ios_base::out|std::ios_base::binary); std::copy( base64_to_bin( my_istream_iterator(ifs &gt;&gt; std::noskipws) ), base64_to_bin( my_istream_iterator() ), my_ostream_iterator(ofs) ); } } </pre><p> Result: 1) If the INPUT FILE will be any of ZIP-file format. The result was: </p> <blockquote> <p> a) _DEBUG_ERROR("istreambuf_iterator is not dereferencable"); <em>it can be disabled or ignored b) The encoded file "test.rez" will have one superfluous byte than INPUT FILE </em></p> </blockquote> <p> 2) If the INPUT FILE will any other file (binary or text) all will be OK. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5630 Trac 1.4.3 anonymous Thu, 23 Jun 2011 11:58:29 GMT <link>https://svn.boost.org/trac10/ticket/5630#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5630#comment:1</guid> <description> <p> The problem description and solution I describe in this topic on RSDN.RU <a class="ext-link" href="http://rsdn.ru/forum/cpp.applied/4315109.aspx"><span class="icon">​</span>http://rsdn.ru/forum/cpp.applied/4315109.aspx</a> </p> </description> <category>Ticket</category> </item> <item> <author>nen777w@…</author> <pubDate>Thu, 23 Jun 2011 13:56:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5630#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5630#comment:2</guid> <description> <p> If it may help. The workaround code and example how to use you can find here: <a class="ext-link" href="http://rsdn.ru/forum/cpp.applied/4317966.1.aspx"><span class="icon">​</span>http://rsdn.ru/forum/cpp.applied/4317966.1.aspx</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Dave Abrahams</dc:creator> <pubDate>Wed, 21 Nov 2012 19:48:55 GMT</pubDate> <title>owner changed https://svn.boost.org/trac10/ticket/5630#comment:3 https://svn.boost.org/trac10/ticket/5630#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Dave Abrahams</span> to <span class="trac-author">jeffrey.hellrung</span> </li> </ul> Ticket Robert Ramey Wed, 21 Nov 2012 19:53:03 GMT owner, status changed https://svn.boost.org/trac10/ticket/5630#comment:4 https://svn.boost.org/trac10/ticket/5630#comment:4 <ul> <li><strong>owner</strong> changed from <span class="trac-author">jeffrey.hellrung</span> to <span class="trac-author">Robert Ramey</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Dave Abrahams Wed, 21 Nov 2012 22:45:40 GMT component changed https://svn.boost.org/trac10/ticket/5630#comment:5 https://svn.boost.org/trac10/ticket/5630#comment:5 <ul> <li><strong>component</strong> <span class="trac-field-old">iterator</span> → <span class="trac-field-new">serialization</span> </li> </ul> Ticket Ferdinand Prantl <prantlf@…> Sat, 07 Sep 2013 11:49:40 GMT <link>https://svn.boost.org/trac10/ticket/5630#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5630#comment:6</guid> <description> <p> The workaround presented above uses a stream wrapper to fix the problem. Another solution could be fixing the transforming iterator. </p> <p> Could this be connected to the transform_width implementation, which works only if the input size is aligned to the unit quantum? If it is not, you'd have to apply/recognize padding correctly: <a class="assigned ticket" href="https://svn.boost.org/trac10/ticket/5629#comment:10" title="#5629: Bugs: base64 encode/decode for std::istreambuf_iterator/std::ostreambuf_iterator (assigned)">ticket:5629#comment:10</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Sun, 22 Feb 2015 21:26:23 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5630#comment:7 https://svn.boost.org/trac10/ticket/5630#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">duplicate</span> </li> </ul> Ticket