[iostreams] Problem with gzip_decompressor

Dear all, Some compressed data was stored in a vector<char> buf (don't know if it's a right way to store compressed data). I used the "buf" as a source, and tried to add a gzip_decompressor to restore those data. I have tried the following approach, but it doesn't work. vector<char> buf; /* fill in the buf */ namespace io = boost::iostreams; io::filtering_istream in(boost::make_iterator_range(buf)); in.push(io::gzip_decompressor()); What I got is an exception, terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector <std::logic_error>>' what(): chain complete Aborted How can I compose a source which comes from a container, and add a gzip_decompressor to the source? Thanks in advance. Regards, chenwj -- Wei-Jen Chen (陳韋任) Programming Language and System Laboratory (EC131) Department of Computer Science, National Chiao Tung University

Yeah, I was awfully confused at first too. In the code I've got working, I use filtering_ostream for both compression and decompression, and use a back_inserter like this: vector<char> comp; bio::filtering_ostream cStream; cStream.push(bio::zlib_compressor() | bio::back_inserter(comp)); cStream.write(decompressedMemory, decompressedSize); vector<char> decomp; bio::filtering_ostream dStream; dStream.push(bio::zlib_decompressor() | bio::back_inserter(decomp)); dStream.write(&comp[0], comp.size()); bio::close(dStream); Brian On Wed, Nov 10, 2010 at 12:42 AM, 陳韋任 <chenwj@cs.nctu.edu.tw> wrote:
Dear all,
Some compressed data was stored in a vector<char> buf (don't know if it's a right way to store compressed data). I used the "buf" as a source, and tried to add a gzip_decompressor to restore those data. I have tried the following approach, but it doesn't work.
vector<char> buf;
/* fill in the buf */
namespace io = boost::iostreams; io::filtering_istream in(boost::make_iterator_range(buf)); in.push(io::gzip_decompressor());
What I got is an exception,
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector <std::logic_error>>' what(): chain complete Aborted
How can I compose a source which comes from a container, and add a gzip_decompressor to the source? Thanks in advance.
Regards, chenwj
-- Wei-Jen Chen (陳韋任) Programming Language and System Laboratory (EC131) Department of Computer Science, National Chiao Tung University
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Thanks for your reply, Brian. I think I have to study your code for a little while. Nevertheless, I had tried out a solution by accident. See below, typedef io::composite<io::gzip_decompressor, io::filtering_istream> array_gzip_decompressor; io::gzip_decompressor filter; io::filtering_istream source(boost::make_iterator_range(buf)); array_gzip_decompressor dev(filter, source); io::stream<array_gzip_decompressor> in(dev); Above code came from http://lists.boost.org/Archives/boost/2010/02/162214.php Regards, chenwj -- Wei-Jen Chen (陳韋任) Programming Language and System Laboratory (EC131) Department of Computer Science, National Chiao Tung University

Hi Chenwj, boost-users-bounces@lists.boost.org on Wednesday, November 10, 2010 9:43 AM:
Dear all,
Some compressed data was stored in a vector<char> buf (don't know if it's a right way to store compressed data). I used the "buf" as a source, and tried to add a gzip_decompressor to restore those data. I have tried the following approach, but it doesn't work.
vector<char> buf;
/* fill in the buf */
namespace io = boost::iostreams; io::filtering_istream in(boost::make_iterator_range(buf)); in.push(io::gzip_decompressor());
What I got is an exception,
terminate called after throwing an instance of
'boost::exception_detail::clone_impl<boost::exception_detail:: error_info_injector <std::logic_error>>' what(): chain complete Aborted
How can I compose a source which comes from a container, and add a gzip_decompressor to the source? Thanks in advance.
Regards, chenwj
it seems to me that "chain complete" is a very precise complaint. To use the filtering_istream you have to reverse natural order and push the source last. Simply try io::filtering_istream in; in.push(io::gzip_decompressor()); in.push(boost::make_iterator_range(buf)); Hope that helps, -- Christian Pfligersdorffer Software Engineering http://www.eos.info

Hi Christian - This is very interesting. What is the difference, if any, between using the filtering_istream and using the filtering_ostream to do compression and decompression? Is there a performance benefit? Is there a conceptually "right" way of doing it? As I mentioned earllier on the thread, I'm using filtering_ostream for both compression and decompression; is this adhering to the library design? Thanks, Brian On Thu, Nov 11, 2010 at 3:49 AM, Pfligersdorffer, Christian <Christian.Pfligersdorffer@eos.info> wrote:
Hi Chenwj,
boost-users-bounces@lists.boost.org on Wednesday, November 10, 2010 9:43 AM:
Dear all,
Some compressed data was stored in a vector<char> buf (don't know if it's a right way to store compressed data). I used the "buf" as a source, and tried to add a gzip_decompressor to restore those data. I have tried the following approach, but it doesn't work.
vector<char> buf;
/* fill in the buf */
namespace io = boost::iostreams; io::filtering_istream in(boost::make_iterator_range(buf)); in.push(io::gzip_decompressor());
What I got is an exception,
terminate called after throwing an instance of
'boost::exception_detail::clone_impl<boost::exception_detail:: error_info_injector <std::logic_error>>' what(): chain complete Aborted
How can I compose a source which comes from a container, and add a gzip_decompressor to the source? Thanks in advance.
Regards, chenwj
it seems to me that "chain complete" is a very precise complaint. To use the filtering_istream you have to reverse natural order and push the source last. Simply try
io::filtering_istream in; in.push(io::gzip_decompressor()); in.push(boost::make_iterator_range(buf));
Hope that helps,
-- Christian Pfligersdorffer Software Engineering http://www.eos.info _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Brian Budge
-
Pfligersdorffer, Christian
-
陳韋任