I have this stream that performs decompression using Boost.Iostreams:
struct istream_zlib
: public boost::iostreams::filtering_stream<boost::iostreams::input, char>
{
istream_zlib(std::istream& in)
{
push(boost::iostreams::zlib_decompressor());
push(in);
}
};
Now, I would like to access the underlying stream (std::istream& in
) later on. Naively, I thought that requesting a std::istream
through component()
would do it, but the pointer I get back is null
:
auto ptr = component<std::istream>(1); // ptr is null!
What type should I provide to component()
for doing that?
It's not real, since not istream
will be pushed into filtering_stream
(for my boost 1.48 it will be boost::iostreams::detail::mode_adapter<boost::iostreams::input, std::istream>
for example), you can check it type by component_type
function. However, I have no ideas, why you need to get stream
from filtering_stream
, since you send reference - you should have this object in places, where you use this filtering_stream
.
Also, you can use reference_wrapper
for this case (i.e push(boost::ref(in));
) and then get it by component using
auto ptr = component<boost::reference_wrapper<std::istream>>(1);