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;
42 /** Creates a zlib de/compression object. The underlying object must be
43 open for reading or writing, not both. The level parameter determines
44 compression quality, ranging from 1 (fastest) to 9 (best compression). */
45 ZlibCompressed(Base &, unsigned level = 9);
47 virtual ~ZlibCompressed();
52 virtual unsigned do_write(const char *, unsigned);
55 /** Compresses data and writes it to the underlying object. Returns true if
56 progress was made, false otherwise. flush_mode can be any of zlib's flush
57 modes. If it is Z_FINISH, false is also returned when the stream has been
59 bool compress_data(int flush_mode);
62 virtual unsigned do_read(char *, unsigned);