]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - misc/mediasource/extra/netradiant-src/plugins/archivezip/zlibstream.h
Rename the compiled fteqcc to fteqcc-win32 (as that's what it is)
[voretournament/voretournament.git] / misc / mediasource / extra / netradiant-src / plugins / archivezip / zlibstream.h
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 #if !defined(INCLUDED_ZLIBSTREAM_H)
23 #define INCLUDED_ZLIBSTREAM_H
24
25 #include "zlib.h"
26 #include "idatastream.h"
27
28 /// \brief A wrapper around an InputStream of data compressed with the zlib deflate algorithm.
29 ///
30 /// - Uses z_stream to decompress the data stream on the fly.
31 /// - Uses a buffer to reduce the number of times the wrapped stream must be read.
32 class DeflatedInputStream : public InputStream
33 {
34   InputStream& m_istream;
35   z_stream m_zipstream;
36   enum unnamed0 { m_bufsize = 1024 };
37   unsigned char m_buffer[m_bufsize];
38
39 public:
40   DeflatedInputStream(InputStream& istream)
41     : m_istream(istream)
42   {
43     m_zipstream.zalloc = 0;
44     m_zipstream.zfree = 0;
45     m_zipstream.opaque = 0;
46     m_zipstream.avail_in = 0;
47     inflateInit2(&m_zipstream, -MAX_WBITS);
48   }
49   ~DeflatedInputStream()
50   {
51     inflateEnd(&m_zipstream);
52   }
53   size_type read(byte_type* buffer, size_type length)
54   {
55     m_zipstream.next_out = buffer;
56     m_zipstream.avail_out = static_cast<uInt>(length);
57     while(m_zipstream.avail_out != 0)
58     {
59       if(m_zipstream.avail_in == 0)
60       {
61         m_zipstream.next_in = m_buffer;
62         m_zipstream.avail_in = static_cast<uInt>(m_istream.read(m_buffer, m_bufsize));
63       }
64       if(inflate(&m_zipstream, Z_SYNC_FLUSH) != Z_OK)
65       {
66         break;
67       }
68     }
69     return length - m_zipstream.avail_out;
70   }
71 };
72
73 #endif
74
75