4
// $Id: //poco/1.2/Foundation/include/Poco/DeflatingStream.h#1 $
10
// Definition of the DeflatingStream class.
12
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
15
// Permission is hereby granted, free of charge, to any person or organization
16
// obtaining a copy of the software and accompanying documentation covered by
17
// this license (the "Software") to use, reproduce, display, distribute,
18
// execute, and transmit the Software, and to prepare derivative works of the
19
// Software, and to permit third-parties to whom the Software is furnished to
20
// do so, all subject to the following:
22
// The copyright notices in the Software and this entire statement, including
23
// the above license grant, this restriction and the following disclaimer,
24
// must be included in all copies of the Software, in whole or in part, and
25
// all derivative works of the Software, unless such copies or derivative
26
// works are solely in the form of machine-executable object code generated by
27
// a source language processor.
29
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35
// DEALINGS IN THE SOFTWARE.
39
#ifndef Foundation_DeflatingStream_INCLUDED
40
#define Foundation_DeflatingStream_INCLUDED
43
#include "Poco/Foundation.h"
44
#include "Poco/BufferedStreamBuf.h"
47
#include "Poco/zlib.h"
53
class Foundation_API DeflatingStreamBuf: public BufferedStreamBuf
54
/// This is the streambuf class used by DeflatingInputStream and DeflatingOutputStream.
55
/// The actual work is delegated to zlib 1.2.1 (see http://www.gzip.org).
56
/// Both zlib (deflate) streams and gzip streams are supported.
57
/// Output streams should always call close() to ensure
58
/// proper completion of compression.
59
/// A compression level (0 to 9) can be specified in the constructor.
68
DeflatingStreamBuf(std::istream& istr, StreamType type, int level);
69
DeflatingStreamBuf(std::ostream& ostr, StreamType type, int level);
70
~DeflatingStreamBuf();
74
int readFromDevice(char* buffer, std::streamsize length);
75
int writeToDevice(const char* buffer, std::streamsize length);
80
STREAM_BUFFER_SIZE = 1024,
81
DEFLATE_BUFFER_SIZE = 32768
92
class Foundation_API DeflatingIOS: public virtual std::ios
93
/// The base class for DeflatingOutputStream and DeflatingInputStream.
95
/// This class is needed to ensure the correct initialization
96
/// order of the stream buffer and base classes.
99
DeflatingIOS(std::ostream& ostr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
100
DeflatingIOS(std::istream& istr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
102
DeflatingStreamBuf* rdbuf();
105
DeflatingStreamBuf _buf;
109
class Foundation_API DeflatingOutputStream: public DeflatingIOS, public std::ostream
110
/// This stream compresses all data passing through it
111
/// using zlib's deflate algorithm.
112
/// After all data has been written to the stream, close()
113
/// must be called to ensure completion of compression.
115
/// std::ofstream ostr("data.gz", std::ios::binary);
116
/// DeflatingOutputStream deflater(ostr, DeflatingStreamBuf::STREAM_GZIP);
117
/// deflater << "Hello, world!" << std::endl;
118
/// deflater.close();
122
DeflatingOutputStream(std::ostream& ostr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
123
~DeflatingOutputStream();
128
class Foundation_API DeflatingInputStream: public DeflatingIOS, public std::istream
129
/// This stream compresses all data passing through it
130
/// using zlib's deflate algorithm.
133
DeflatingInputStream(std::istream& istr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
134
~DeflatingInputStream();
141
#endif // Foundation_DeflatingStream_INCLUDED