zfstream
zfstream is a small C++ library which provides an abstraction API for
reading and writing compressed and non-compressed files using the same
API. It supports libz and libbz2 compression schemes and is based
upon
the gzstream class written by Deepak Bandyopadhyay and Lutz Kettner.
The library is trivial to use and provides
client applications with a unified interface for reading and writing
files without having to know whether they are compressed or not.
This library provides, for example, the client-transparent compression
support in
libs11n.
As far as external dependencies go: it relies on the STL and one or both
of libz and/or libbzip2.
License: GNU Lesser/Library General Public License (LGPL)
You can download the sources here:
Code sample:
#include <s11n.net/zfstream/zfstream.hpp>
...
//////////////////// Input stream:
std::auto_ptr<std::istream> istr =
zfstream::get_istream( "/path/to/file" );
if( ! istr.get() ) { ... error ... }
// istr might be compressed or might not - we don't care.
//////////////////// Output stream:
// For writing compressed files, we register a preference/policy
// with the library (the default policy is not to compress streams):
zfstream::compression_policy( zfstream::ZLibCompression );
...
std::auto_ptr<std::ostream> ostr =
zfstream::get_ostream( "/path/to/file" );
if( ! ostr.get() ) { ... error ... }
// We can now write to ostr using the standard ostream API, without
// caring about whether it's compressed or not.
Compiling and linking client code
When compiling, add the top-level includes path under which you install zfstream to
your compiler's INCLUDES option. e.g., if you install under
/opt
then add
-I/opt/include to your INCLUDES and in your client code
to
#include <s11n.net/zfstream/zfstream.hpp>.
To link your client code, simply link against libs11n_zfstream, normally by passing, for example,
-L/opt/lib -ls11n_zfstream. You may also need to link against libz
and/or libbz2 - zfstream requires at least one of these in order to be functional.