]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) | |
3 | // | |
4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | // | |
7 | // This is a derivative work based on Zlib, copyright below: | |
8 | /* | |
9 | Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler | |
10 | ||
11 | This software is provided 'as-is', without any express or implied | |
12 | warranty. In no event will the authors be held liable for any damages | |
13 | arising from the use of this software. | |
14 | ||
15 | Permission is granted to anyone to use this software for any purpose, | |
16 | including commercial applications, and to alter it and redistribute it | |
17 | freely, subject to the following restrictions: | |
18 | ||
19 | 1. The origin of this software must not be misrepresented; you must not | |
20 | claim that you wrote the original software. If you use this software | |
21 | in a product, an acknowledgment in the product documentation would be | |
22 | appreciated but is not required. | |
23 | 2. Altered source versions must be plainly marked as such, and must not be | |
24 | misrepresented as being the original software. | |
25 | 3. This notice may not be removed or altered from any source distribution. | |
26 | ||
27 | Jean-loup Gailly Mark Adler | |
28 | jloup@gzip.org madler@alumni.caltech.edu | |
29 | ||
30 | The data format used by the zlib library is described by RFCs (Request for | |
31 | Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 | |
32 | (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). | |
33 | */ | |
34 | ||
35 | #ifndef BEAST_ZLIB_ZLIB_HPP | |
36 | #define BEAST_ZLIB_ZLIB_HPP | |
37 | ||
38 | #include <beast/config.hpp> | |
39 | #include <cstdint> | |
40 | #include <cstdlib> | |
41 | ||
42 | namespace beast { | |
43 | namespace zlib { | |
44 | ||
45 | #if !defined(__MACTYPES__) | |
46 | typedef unsigned char Byte; /* 8 bits */ | |
47 | #endif | |
48 | typedef unsigned int uInt; /* 16 bits or more */ | |
49 | ||
50 | /* Possible values of the data_type field (though see inflate()) */ | |
51 | enum z_Type | |
52 | { | |
53 | Z_BINARY = 0, | |
54 | Z_TEXT = 1, | |
55 | Z_UNKNOWN = 2 | |
56 | }; | |
57 | ||
58 | /** Deflate codec parameters. | |
59 | ||
60 | Objects of this type are filled in by callers and provided to the | |
61 | deflate codec to define the input and output areas for the next | |
62 | compress or decompress operation. | |
63 | ||
64 | The application must update next_in and avail_in when avail_in has dropped | |
65 | to zero. It must update next_out and avail_out when avail_out has dropped | |
66 | to zero. The application must initialize zalloc, zfree and opaque before | |
67 | calling the init function. All other fields are set by the compression | |
68 | library and must not be updated by the application. | |
69 | ||
70 | The fields total_in and total_out can be used for statistics or progress | |
71 | reports. After compression, total_in holds the total size of the | |
72 | uncompressed data and may be saved for use in the decompressor (particularly | |
73 | if the decompressor wants to decompress everything in a single step). | |
74 | */ | |
75 | struct z_params | |
76 | { | |
77 | /** A pointer to the next input byte. | |
78 | ||
79 | If there is no more input, this may be set to `nullptr`. | |
80 | */ | |
81 | void const* next_in; | |
82 | ||
83 | /** The number of bytes of input available at `next_in`. | |
84 | ||
85 | If there is no more input, this should be set to zero. | |
86 | */ | |
87 | std::size_t avail_in; | |
88 | ||
89 | /** The total number of input bytes read so far. | |
90 | */ | |
91 | std::size_t total_in = 0; | |
92 | ||
93 | /** A pointer to the next output byte. | |
94 | */ | |
95 | void* next_out; | |
96 | ||
97 | /** The remaining bytes of space at `next_out`. | |
98 | */ | |
99 | std::size_t avail_out; | |
100 | ||
101 | /** The total number of bytes output so far. | |
102 | */ | |
103 | std::size_t total_out = 0; | |
104 | ||
105 | int data_type = Z_UNKNOWN; // best guess about the data type: binary or text | |
106 | }; | |
107 | ||
108 | /** Flush option. | |
109 | */ | |
110 | enum class Flush | |
111 | { | |
112 | // order matters | |
113 | ||
114 | none, | |
115 | block, | |
116 | partial, | |
117 | sync, | |
118 | full, | |
119 | finish, | |
120 | trees | |
121 | }; | |
122 | ||
123 | /* compression levels */ | |
124 | enum z_Compression | |
125 | { | |
126 | Z_NO_COMPRESSION = 0, | |
127 | Z_BEST_SPEED = 1, | |
128 | Z_BEST_COMPRESSION = 9, | |
129 | Z_DEFAULT_COMPRESSION = -1 | |
130 | }; | |
131 | ||
132 | /** Compression strategy. | |
133 | ||
134 | These are used when compressing streams. | |
135 | */ | |
136 | enum class Strategy | |
137 | { | |
138 | /** Default strategy. | |
139 | ||
140 | This is suitable for general purpose compression, and works | |
141 | well in the majority of cases. | |
142 | */ | |
143 | normal, | |
144 | ||
145 | /** Filtered strategy. | |
146 | ||
147 | This strategy should be used when the data be compressed | |
148 | is produced by a filter or predictor. | |
149 | */ | |
150 | filtered, | |
151 | ||
152 | /** Huffman-only strategy. | |
153 | ||
154 | This strategy only performs Huffman encoding, without doing | |
155 | any string matching. | |
156 | */ | |
157 | huffman, | |
158 | ||
159 | /** Run Length Encoding strategy. | |
160 | ||
161 | This strategy limits match distances to one, making it | |
162 | equivalent to run length encoding. This can give better | |
163 | performance for things like PNG image data. | |
164 | */ | |
165 | rle, | |
166 | ||
167 | /** Fixed table strategy. | |
168 | ||
169 | This strategy prevents the use of dynamic Huffman codes, | |
170 | allowing for a simpler decoder for special applications. | |
171 | */ | |
172 | fixed | |
173 | }; | |
174 | ||
175 | } // zlib | |
176 | } // beast | |
177 | ||
178 | #endif | |
179 |