Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60415 - in trunk: boost/iostreams/filter libs/iostreams/test
From: daniel_james_at_[hidden]
Date: 2010-03-10 02:29:44


Author: danieljames
Date: 2010-03-10 02:29:44 EST (Wed, 10 Mar 2010)
New Revision: 60415
URL: http://svn.boost.org/trac/boost/changeset/60415

Log:
Gzip filter shouldn't require its source to be peekable. Refs #3723.

In a recent version, the gzip filter stopped working for array sources,
this is because it started to require them to be peekable, which they
aren't and can't be because the peek interface modifies the source,
which for an array source is immutable.

Looking at the implementation, gzip decompressor has an internal class
to emulate a peekable source, which calls the putback member on the
original source if it runs out of space (requiring the source to be
peekable). It shouldn't really need to do that so I changed it to throw
an exception instead.

If it does need to do that, we could change it to store the character
that was put back at the beginning of the string instead.
Text files modified:
   trunk/boost/iostreams/filter/gzip.hpp | 6 ++++--
   trunk/libs/iostreams/test/gzip_test.cpp | 18 ++++++++++++++++++
   2 files changed, 22 insertions(+), 2 deletions(-)

Modified: trunk/boost/iostreams/filter/gzip.hpp
==============================================================================
--- trunk/boost/iostreams/filter/gzip.hpp (original)
+++ trunk/boost/iostreams/filter/gzip.hpp 2010-03-10 02:29:44 EST (Wed, 10 Mar 2010)
@@ -32,6 +32,7 @@
 #include <boost/iostreams/detail/adapter/range_adapter.hpp>
 #include <boost/iostreams/detail/char_traits.hpp>
 #include <boost/iostreams/detail/ios.hpp> // failure.
+#include <boost/iostreams/detail/error.hpp>
 #include <boost/iostreams/operations.hpp>
 #include <boost/iostreams/device/back_inserter.hpp>
 #include <boost/iostreams/filter/zlib.hpp>
@@ -531,10 +532,11 @@
         {
             if (offset_) {
                 putback_[--offset_] = c;
- return true;
             } else {
- return boost::iostreams::putback(src_, c);
+ boost::throw_exception(
+ boost::iostreams::detail::bad_putback());
             }
+ return true;
         }
         void putback(const string_type& s)
         {

Modified: trunk/libs/iostreams/test/gzip_test.cpp
==============================================================================
--- trunk/libs/iostreams/test/gzip_test.cpp (original)
+++ trunk/libs/iostreams/test/gzip_test.cpp 2010-03-10 02:29:44 EST (Wed, 10 Mar 2010)
@@ -83,10 +83,28 @@
     BOOST_CHECK(std::equal(data.begin(), data.end(), dest.begin() + dest.size() / 2));
 }
 
+void array_source_test()
+{
+ std::string data = "simple test string.";
+ std::string encoded;
+
+ filtering_ostream out;
+ out.push(gzip_compressor());
+ out.push(io::back_inserter(encoded));
+ io::copy(make_iterator_range(data), out);
+
+ std::string res;
+ io::array_source src(encoded.data(),encoded.length());
+ io::copy(io::compose(io::gzip_decompressor(), src), io::back_inserter(res));
+
+ BOOST_CHECK_EQUAL(data, res);
+}
+
 test_suite* init_unit_test_suite(int, char* [])
 {
     test_suite* test = BOOST_TEST_SUITE("gzip test");
     test->add(BOOST_TEST_CASE(&compression_test));
     test->add(BOOST_TEST_CASE(&multiple_member_test));
+ test->add(BOOST_TEST_CASE(&array_source_test));
     return test;
 }


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