Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63057 - in trunk: boost/iostreams/filter libs/iostreams/test
From: steven_at_[hidden]
Date: 2010-06-17 15:14:16


Author: steven_watanabe
Date: 2010-06-17 15:14:14 EDT (Thu, 17 Jun 2010)
New Revision: 63057
URL: http://svn.boost.org/trac/boost/changeset/63057

Log:
Allow bzip2_decompressor to process multiple concatenated streams. Fixes #3853.
Text files modified:
   trunk/boost/iostreams/filter/bzip2.hpp | 12 +++++++++---
   trunk/libs/iostreams/test/bzip2_test.cpp | 37 +++++++++++++++++++++++++++++++++++++
   trunk/libs/iostreams/test/gzip_test.cpp | 11 +++++++++++
   3 files changed, 57 insertions(+), 3 deletions(-)

Modified: trunk/boost/iostreams/filter/bzip2.hpp
==============================================================================
--- trunk/boost/iostreams/filter/bzip2.hpp (original)
+++ trunk/boost/iostreams/filter/bzip2.hpp 2010-06-17 15:14:14 EDT (Thu, 17 Jun 2010)
@@ -350,17 +350,23 @@
     ( const char*& src_begin, const char* src_end,
       char*& dest_begin, char* dest_end, bool flush )
 {
+ if (eof_) {
+ // reset the stream if there are more characters
+ if(src_begin == src_end)
+ return false;
+ else
+ close();
+ }
     if (!ready())
         init();
- if (eof_)
- return false;
     before(src_begin, src_end, dest_begin, dest_end);
     int result = decompress();
     if(result == bzip2::ok && flush)
         result = check_end(src_begin, dest_begin);
     after(src_begin, dest_begin);
     bzip2_error::check BOOST_PREVENT_MACRO_SUBSTITUTION(result);
- return !(eof_ = result == bzip2::stream_end);
+ eof_ = result == bzip2::stream_end;
+ return true;
 }
 
 template<typename Alloc>

Modified: trunk/libs/iostreams/test/bzip2_test.cpp
==============================================================================
--- trunk/libs/iostreams/test/bzip2_test.cpp (original)
+++ trunk/libs/iostreams/test/bzip2_test.cpp 2010-06-17 15:14:14 EDT (Thu, 17 Jun 2010)
@@ -18,6 +18,7 @@
 using namespace boost::iostreams;
 using namespace boost::iostreams::test;
 using boost::unit_test::test_suite;
+namespace io = boost::iostreams;
 
 struct bzip2_alloc : std::allocator<char> { };
 
@@ -51,9 +52,45 @@
     }
 }
 
+void multiple_member_test()
+{
+ text_sequence data;
+ std::vector<char> temp, dest;
+
+ // Write compressed data to temp, twice in succession
+ filtering_ostream out;
+ out.push(bzip2_compressor());
+ out.push(io::back_inserter(temp));
+ io::copy(make_iterator_range(data), out);
+ out.push(io::back_inserter(temp));
+ io::copy(make_iterator_range(data), out);
+
+ // Read compressed data from temp into dest
+ filtering_istream in;
+ in.push(bzip2_decompressor());
+ in.push(array_source(&temp[0], temp.size()));
+ io::copy(in, io::back_inserter(dest));
+
+ // Check that dest consists of two copies of data
+ BOOST_REQUIRE_EQUAL(data.size() * 2, dest.size());
+ BOOST_CHECK(std::equal(data.begin(), data.end(), dest.begin()));
+ BOOST_CHECK(std::equal(data.begin(), data.end(), dest.begin() + dest.size() / 2));
+
+ dest.clear();
+ io::copy(
+ array_source(&temp[0], temp.size()),
+ io::compose(bzip2_decompressor(), io::back_inserter(dest)));
+
+ // Check that dest consists of two copies of data
+ BOOST_REQUIRE_EQUAL(data.size() * 2, dest.size());
+ BOOST_CHECK(std::equal(data.begin(), data.end(), dest.begin()));
+ BOOST_CHECK(std::equal(data.begin(), data.end(), dest.begin() + dest.size() / 2));
+}
+
 test_suite* init_unit_test_suite(int, char* [])
 {
     test_suite* test = BOOST_TEST_SUITE("bzip2 test");
     test->add(BOOST_TEST_CASE(&bzip2_test));
+ test->add(BOOST_TEST_CASE(&multiple_member_test));
     return test;
 }

Modified: trunk/libs/iostreams/test/gzip_test.cpp
==============================================================================
--- trunk/libs/iostreams/test/gzip_test.cpp (original)
+++ trunk/libs/iostreams/test/gzip_test.cpp 2010-06-17 15:14:14 EDT (Thu, 17 Jun 2010)
@@ -79,6 +79,17 @@
     io::copy(in, io::back_inserter(dest));
 
     // Check that dest consists of two copies of data
+ BOOST_REQUIRE_EQUAL(data.size() * 2, dest.size());
+ BOOST_CHECK(std::equal(data.begin(), data.end(), dest.begin()));
+ BOOST_CHECK(std::equal(data.begin(), data.end(), dest.begin() + dest.size() / 2));
+
+ dest.clear();
+ io::copy(
+ array_source(&temp[0], temp.size()),
+ io::compose(gzip_decompressor(), io::back_inserter(dest)));
+
+ // Check that dest consists of two copies of data
+ BOOST_REQUIRE_EQUAL(data.size() * 2, dest.size());
     BOOST_CHECK(std::equal(data.begin(), data.end(), dest.begin()));
     BOOST_CHECK(std::equal(data.begin(), data.end(), dest.begin() + dest.size() / 2));
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk