source: XMLIO_V2/external/src/POCO/Foundation.save/Poco/DeflatingStream.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1//
2// DeflatingStream.h
3//
4// $Id: //poco/1.3/Foundation/include/Poco/DeflatingStream.h#2 $
5//
6// Library: Foundation
7// Package: Streams
8// Module:  ZLibStream
9//
10// Definition of the DeflatingStream class.
11//
12// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
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:
21//
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.
28//
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.
36//
37
38
39#ifndef Foundation_DeflatingStream_INCLUDED
40#define Foundation_DeflatingStream_INCLUDED
41
42
43#include "Poco/Foundation.h"
44#include "Poco/BufferedStreamBuf.h"
45#include <istream>
46#include <ostream>
47#if defined(POCO_UNBUNDLED)
48#include <zlib.h>
49#else
50#include "Poco/zlib.h"
51#endif
52
53
54namespace Poco {
55
56
57class Foundation_API DeflatingStreamBuf: public BufferedStreamBuf
58        /// This is the streambuf class used by DeflatingInputStream and DeflatingOutputStream.
59        /// The actual work is delegated to zlib 1.2.1 (see http://www.gzip.org).
60        /// Both zlib (deflate) streams and gzip streams are supported.
61        /// Output streams should always call close() to ensure
62        /// proper completion of compression.
63        /// A compression level (0 to 9) can be specified in the constructor.
64{
65public:
66        enum StreamType
67        {
68                STREAM_ZLIB,
69                STREAM_GZIP
70        };
71
72        DeflatingStreamBuf(std::istream& istr, StreamType type, int level);
73        DeflatingStreamBuf(std::ostream& ostr, StreamType type, int level);
74        ~DeflatingStreamBuf();
75        int close();
76
77protected:
78        int readFromDevice(char* buffer, std::streamsize length);
79        int writeToDevice(const char* buffer, std::streamsize length);
80
81private:
82        enum 
83        {
84                STREAM_BUFFER_SIZE  = 1024,
85                DEFLATE_BUFFER_SIZE = 32768
86        };
87
88        std::istream* _pIstr;
89        std::ostream* _pOstr;
90        char*    _buffer;
91        z_stream _zstr;
92        bool     _eof;
93};
94
95
96class Foundation_API DeflatingIOS: public virtual std::ios
97        /// The base class for DeflatingOutputStream and DeflatingInputStream.
98        ///
99        /// This class is needed to ensure the correct initialization
100        /// order of the stream buffer and base classes.
101{
102public:
103        DeflatingIOS(std::ostream& ostr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
104        DeflatingIOS(std::istream& istr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
105        ~DeflatingIOS();
106        DeflatingStreamBuf* rdbuf();
107
108protected:
109        DeflatingStreamBuf _buf;
110};
111
112
113class Foundation_API DeflatingOutputStream: public DeflatingIOS, public std::ostream
114        /// This stream compresses all data passing through it
115        /// using zlib's deflate algorithm.
116        /// After all data has been written to the stream, close()
117        /// must be called to ensure completion of compression.
118        /// Example:
119        ///     std::ofstream ostr("data.gz", std::ios::binary);
120        ///     DeflatingOutputStream deflater(ostr, DeflatingStreamBuf::STREAM_GZIP);
121        ///     deflater << "Hello, world!" << std::endl;
122        ///     deflater.close();
123        ///     ostr.close();
124{
125public:
126        DeflatingOutputStream(std::ostream& ostr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
127        ~DeflatingOutputStream();
128        int close();
129};
130
131
132class Foundation_API DeflatingInputStream: public DeflatingIOS, public std::istream
133        /// This stream compresses all data passing through it
134        /// using zlib's deflate algorithm.
135{
136public:
137        DeflatingInputStream(std::istream& istr, DeflatingStreamBuf::StreamType type = DeflatingStreamBuf::STREAM_ZLIB, int level = Z_DEFAULT_COMPRESSION);
138        ~DeflatingInputStream();
139};
140
141
142} // namespace Poco
143
144
145#endif // Foundation_DeflatingStream_INCLUDED
Note: See TracBrowser for help on using the repository browser.