1 #ifndef MSP_IO_ZLIBCOMPRESSED_H_
2 #define MSP_IO_ZLIBCOMPRESSED_H_
11 class zlib_error: public std::runtime_error
17 zlib_error(const std::string &, int);
18 ~zlib_error() throw() { }
20 int code() const throw() { return code_; }
24 Compresses or decompresses data with zlib. This class is a filter that
25 operates on top of another I/O object.
27 To ensure proper termination of the compressed data stream, the ZlibCompressed
28 object must be destroyed before the underlying object is closed.
30 class ZlibCompressed: public Base
37 unsigned char *in_buffer;
38 unsigned char *out_buffer;
43 /** Creates a zlib de/compression object. The underlying object must be
44 open for reading or writing, not both. The level parameter determines
45 compression quality, ranging from 1 (fastest) to 9 (best compression). */
46 ZlibCompressed(Base &, unsigned level = 9);
48 virtual ~ZlibCompressed();
53 virtual unsigned do_write(const char *, unsigned);
56 /** Compresses data and writes it to the underlying object. Returns true if
57 progress was made, false otherwise. flush_mode can be any of zlib's flush
58 modes. If it is Z_FINISH, false is also returned when the stream has been
60 bool compress_data(int flush_mode);
63 virtual unsigned do_read(char *, unsigned);