Opened 11 years ago
Closed 8 years ago
#5630 closed Bugs (duplicate)
base64 encode/decode for std::istreambuf_iterator/std::ostreambuf_iterator
Reported by: | Owned by: | Robert Ramey | |
---|---|---|---|
Milestone: | To Be Determined | Component: | serialization |
Version: | Boost 1.45.0 | Severity: | Problem |
Keywords: | Cc: |
Description
MSVS 2008 The code:
#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<char> my_istream_iterator; typedef std::ostreambuf_iterator<char> my_ostream_iterator; typedef boost::archive::iterators::base64_from_binary< boost::archive::iterators::transform_width< my_istream_iterator, 6, 8> > bin_to_base64; typedef boost::archive::iterators::transform_width< boost::archive::iterators::binary_from_base64< my_istream_iterator >, 8, 6 > 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 >> 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 >> std::noskipws) ), base64_to_bin( my_istream_iterator() ), my_ostream_iterator(ofs) ); } }
Result: 1) If the INPUT FILE will be any of ZIP-file format. The result was:
a) _DEBUG_ERROR("istreambuf_iterator is not dereferencable"); it can be disabled or ignored b) The encoded file "test.rez" will have one superfluous byte than INPUT FILE
2) If the INPUT FILE will any other file (binary or text) all will be OK.
Change History (7)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
If it may help. The workaround code and example how to use you can find here: http://rsdn.ru/forum/cpp.applied/4317966.1.aspx
comment:3 by , 10 years ago
Owner: | changed from | to
---|
comment:4 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 10 years ago
Component: | iterator → serialization |
---|
comment:6 by , 9 years ago
The workaround presented above uses a stream wrapper to fix the problem. Another solution could be fixing the transforming iterator.
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: ticket:5629#comment:10.
comment:7 by , 8 years ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
The problem description and solution I describe in this topic on RSDN.RU http://rsdn.ru/forum/cpp.applied/4315109.aspx