|
Boost Users : |
From: Marc Viala Perso (marc.viala_at_[hidden])
Date: 2008-01-18 16:08:54
Hello,
I'm just wondering why zlib and bzip2 codec are "dual_use" filter but not
gzip? Can anybody enlighten me on this restriction?
In fact, I have the following use case:
I need to manage an "iostream" instance for interfacing with an external
library but I would like to be able to support the GZIP codec during
writing/reading operations, that is, I must deal with the following
"external" serializer engine:
SerializerEngine ar(std::iostream& ios, OpeningMode mode)
The SerializerEngine interface provides some read/write raw
operations.
For doing that, I've just tried to implement the following class:
class gzfstream: public
boost::iostreams::filtering_stream<boost::iostreams::dual_use>
{
public:
template <class Path>
gzfstream(const Path& file_path, std::ios_base::openmode mode):
_file(file_path, mode)
{
if( _file.fail() ) return ;
namespace fs = boost::filesystem ;
namespace io = boost::iostreams ;
const typename Path::string_type& ext = fs::extension(file_path) ;
if( gz_extension_exists(ext) ) {
const bool in_op = (mode & std::ios::in) != 0 ;
const bool out_op = (mode & std::ios::out) != 0 ;
if( in_op && out_op )
throw std::logic_error("can't support input/output operation with
codec") ;
if( out_op ) push(io::gzip_compressor()) ;
else push(io::gzip_decompressor()) ;
}
push(_file) ;
}
~gzfstream()
{ reset() ; }
private:
boost::filesystem::fstream _file ;
bool gz_extension_exists(const std::string& ext)
{ return ext.size() == 3 && ext == ".gz" ; }
bool gz_extension_exists(const std::wstring& ext)
{ return ext.size() == 3 && ext == L".gz" ; }
} ;
But this class doesn't compile only for GZIP codec because, as explained in
the documentation, GZIP doesn't support dual_use concept - contrary to the
ZLib and BZip2 codecs. Is there any issue to deal with my use case?
Any help will be appreciate?
Best regards,
Marc VIALA
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net