zstdlib 0.1.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.md +9 -0
- data/Gemfile +3 -0
- data/README.md +96 -0
- data/Rakefile +29 -0
- data/ext/zstdlib/extconf.rb +53 -0
- data/ext/zstdlib/ruby/zlib-2.2/zlib.c +4659 -0
- data/ext/zstdlib/ruby/zlib-2.3/zlib.c +4686 -0
- data/ext/zstdlib/ruby/zlib-2.4/zlib.c +4843 -0
- data/ext/zstdlib/ruby/zlib-2.5/zlib.c +4848 -0
- data/ext/zstdlib/ruby/zlib-2.6/zlib.c +4890 -0
- data/ext/zstdlib/zlib-1.2.11/adler32.c +186 -0
- data/ext/zstdlib/zlib-1.2.11/compress.c +86 -0
- data/ext/zstdlib/zlib-1.2.11/crc32.c +442 -0
- data/ext/zstdlib/zlib-1.2.11/crc32.h +441 -0
- data/ext/zstdlib/zlib-1.2.11/deflate.c +2163 -0
- data/ext/zstdlib/zlib-1.2.11/deflate.h +349 -0
- data/ext/zstdlib/zlib-1.2.11/gzclose.c +25 -0
- data/ext/zstdlib/zlib-1.2.11/gzguts.h +218 -0
- data/ext/zstdlib/zlib-1.2.11/gzlib.c +637 -0
- data/ext/zstdlib/zlib-1.2.11/gzread.c +654 -0
- data/ext/zstdlib/zlib-1.2.11/gzwrite.c +665 -0
- data/ext/zstdlib/zlib-1.2.11/infback.c +640 -0
- data/ext/zstdlib/zlib-1.2.11/inffast.c +323 -0
- data/ext/zstdlib/zlib-1.2.11/inffast.h +11 -0
- data/ext/zstdlib/zlib-1.2.11/inffixed.h +94 -0
- data/ext/zstdlib/zlib-1.2.11/inflate.c +1561 -0
- data/ext/zstdlib/zlib-1.2.11/inflate.h +125 -0
- data/ext/zstdlib/zlib-1.2.11/inftrees.c +304 -0
- data/ext/zstdlib/zlib-1.2.11/inftrees.h +62 -0
- data/ext/zstdlib/zlib-1.2.11/trees.c +1203 -0
- data/ext/zstdlib/zlib-1.2.11/trees.h +128 -0
- data/ext/zstdlib/zlib-1.2.11/uncompr.c +93 -0
- data/ext/zstdlib/zlib-1.2.11/zconf.h +534 -0
- data/ext/zstdlib/zlib-1.2.11/zlib.h +1912 -0
- data/ext/zstdlib/zlib-1.2.11/zutil.c +325 -0
- data/ext/zstdlib/zlib-1.2.11/zutil.h +271 -0
- data/ext/zstdlib/zlib.mk +14 -0
- data/ext/zstdlib/zlibwrapper.mk +14 -0
- data/ext/zstdlib/zlibwrapper/zlibwrapper.c +14 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/bitstream.h +455 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/compiler.h +140 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/cpu.h +215 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/debug.c +44 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/debug.h +134 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/entropy_common.c +236 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.c +54 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.h +76 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/fse.h +708 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/fse_decompress.c +309 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/huf.h +358 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/mem.h +380 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/pool.c +340 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/pool.h +84 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/threading.c +75 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/threading.h +123 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.c +876 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.h +305 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_common.c +83 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_errors.h +93 -0
- data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_internal.h +266 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/fse_compress.c +721 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.c +203 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.h +95 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/huf_compress.c +798 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress.c +4290 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress_internal.h +860 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.c +499 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.h +38 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.c +391 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.h +37 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.c +1106 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.h +67 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.c +597 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.h +105 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.c +1217 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.h +56 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.c +2107 -0
- data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.h +174 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/huf_decompress.c +1232 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.c +240 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.h +44 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress.c +1672 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.c +1307 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.h +59 -0
- data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_internal.h +168 -0
- data/ext/zstdlib/zstd-1.3.8/lib/zstd.h +1766 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzclose.c +28 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzcompatibility.h +68 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzguts.h +227 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzlib.c +640 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzread.c +670 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzwrite.c +671 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.c +1105 -0
- data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.h +88 -0
- data/ext/zstdlib/zstd.mk +14 -0
- data/lib/2.2/zstdlib.so +0 -0
- data/lib/2.3/zstdlib.so +0 -0
- data/lib/2.4/zstdlib.so +0 -0
- data/lib/2.5/zstdlib.so +0 -0
- data/lib/2.6/zstdlib.so +0 -0
- data/lib/zstdlib.rb +6 -0
- data/test/zstdlib_test.rb +21 -0
- metadata +205 -0
@@ -0,0 +1,349 @@
|
|
1
|
+
/* deflate.h -- internal compression state
|
2
|
+
* Copyright (C) 1995-2016 Jean-loup Gailly
|
3
|
+
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
|
+
*/
|
5
|
+
|
6
|
+
/* WARNING: this file should *not* be used by applications. It is
|
7
|
+
part of the implementation of the compression library and is
|
8
|
+
subject to change. Applications should only use zlib.h.
|
9
|
+
*/
|
10
|
+
|
11
|
+
/* @(#) $Id$ */
|
12
|
+
|
13
|
+
#ifndef DEFLATE_H
|
14
|
+
#define DEFLATE_H
|
15
|
+
|
16
|
+
#include "zutil.h"
|
17
|
+
|
18
|
+
/* define NO_GZIP when compiling if you want to disable gzip header and
|
19
|
+
trailer creation by deflate(). NO_GZIP would be used to avoid linking in
|
20
|
+
the crc code when it is not needed. For shared libraries, gzip encoding
|
21
|
+
should be left enabled. */
|
22
|
+
#ifndef NO_GZIP
|
23
|
+
# define GZIP
|
24
|
+
#endif
|
25
|
+
|
26
|
+
/* ===========================================================================
|
27
|
+
* Internal compression state.
|
28
|
+
*/
|
29
|
+
|
30
|
+
#define LENGTH_CODES 29
|
31
|
+
/* number of length codes, not counting the special END_BLOCK code */
|
32
|
+
|
33
|
+
#define LITERALS 256
|
34
|
+
/* number of literal bytes 0..255 */
|
35
|
+
|
36
|
+
#define L_CODES (LITERALS+1+LENGTH_CODES)
|
37
|
+
/* number of Literal or Length codes, including the END_BLOCK code */
|
38
|
+
|
39
|
+
#define D_CODES 30
|
40
|
+
/* number of distance codes */
|
41
|
+
|
42
|
+
#define BL_CODES 19
|
43
|
+
/* number of codes used to transfer the bit lengths */
|
44
|
+
|
45
|
+
#define HEAP_SIZE (2*L_CODES+1)
|
46
|
+
/* maximum heap size */
|
47
|
+
|
48
|
+
#define MAX_BITS 15
|
49
|
+
/* All codes must not exceed MAX_BITS bits */
|
50
|
+
|
51
|
+
#define Buf_size 16
|
52
|
+
/* size of bit buffer in bi_buf */
|
53
|
+
|
54
|
+
#define INIT_STATE 42 /* zlib header -> BUSY_STATE */
|
55
|
+
#ifdef GZIP
|
56
|
+
# define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
|
57
|
+
#endif
|
58
|
+
#define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
|
59
|
+
#define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
|
60
|
+
#define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
|
61
|
+
#define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
|
62
|
+
#define BUSY_STATE 113 /* deflate -> FINISH_STATE */
|
63
|
+
#define FINISH_STATE 666 /* stream complete */
|
64
|
+
/* Stream status */
|
65
|
+
|
66
|
+
|
67
|
+
/* Data structure describing a single value and its code string. */
|
68
|
+
typedef struct ct_data_s {
|
69
|
+
union {
|
70
|
+
ush freq; /* frequency count */
|
71
|
+
ush code; /* bit string */
|
72
|
+
} fc;
|
73
|
+
union {
|
74
|
+
ush dad; /* father node in Huffman tree */
|
75
|
+
ush len; /* length of bit string */
|
76
|
+
} dl;
|
77
|
+
} FAR ct_data;
|
78
|
+
|
79
|
+
#define Freq fc.freq
|
80
|
+
#define Code fc.code
|
81
|
+
#define Dad dl.dad
|
82
|
+
#define Len dl.len
|
83
|
+
|
84
|
+
typedef struct static_tree_desc_s static_tree_desc;
|
85
|
+
|
86
|
+
typedef struct tree_desc_s {
|
87
|
+
ct_data *dyn_tree; /* the dynamic tree */
|
88
|
+
int max_code; /* largest code with non zero frequency */
|
89
|
+
const static_tree_desc *stat_desc; /* the corresponding static tree */
|
90
|
+
} FAR tree_desc;
|
91
|
+
|
92
|
+
typedef ush Pos;
|
93
|
+
typedef Pos FAR Posf;
|
94
|
+
typedef unsigned IPos;
|
95
|
+
|
96
|
+
/* A Pos is an index in the character window. We use short instead of int to
|
97
|
+
* save space in the various tables. IPos is used only for parameter passing.
|
98
|
+
*/
|
99
|
+
|
100
|
+
typedef struct internal_state {
|
101
|
+
z_streamp strm; /* pointer back to this zlib stream */
|
102
|
+
int status; /* as the name implies */
|
103
|
+
Bytef *pending_buf; /* output still pending */
|
104
|
+
ulg pending_buf_size; /* size of pending_buf */
|
105
|
+
Bytef *pending_out; /* next pending byte to output to the stream */
|
106
|
+
ulg pending; /* nb of bytes in the pending buffer */
|
107
|
+
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
|
108
|
+
gz_headerp gzhead; /* gzip header information to write */
|
109
|
+
ulg gzindex; /* where in extra, name, or comment */
|
110
|
+
Byte method; /* can only be DEFLATED */
|
111
|
+
int last_flush; /* value of flush param for previous deflate call */
|
112
|
+
|
113
|
+
/* used by deflate.c: */
|
114
|
+
|
115
|
+
uInt w_size; /* LZ77 window size (32K by default) */
|
116
|
+
uInt w_bits; /* log2(w_size) (8..16) */
|
117
|
+
uInt w_mask; /* w_size - 1 */
|
118
|
+
|
119
|
+
Bytef *window;
|
120
|
+
/* Sliding window. Input bytes are read into the second half of the window,
|
121
|
+
* and move to the first half later to keep a dictionary of at least wSize
|
122
|
+
* bytes. With this organization, matches are limited to a distance of
|
123
|
+
* wSize-MAX_MATCH bytes, but this ensures that IO is always
|
124
|
+
* performed with a length multiple of the block size. Also, it limits
|
125
|
+
* the window size to 64K, which is quite useful on MSDOS.
|
126
|
+
* To do: use the user input buffer as sliding window.
|
127
|
+
*/
|
128
|
+
|
129
|
+
ulg window_size;
|
130
|
+
/* Actual size of window: 2*wSize, except when the user input buffer
|
131
|
+
* is directly used as sliding window.
|
132
|
+
*/
|
133
|
+
|
134
|
+
Posf *prev;
|
135
|
+
/* Link to older string with same hash index. To limit the size of this
|
136
|
+
* array to 64K, this link is maintained only for the last 32K strings.
|
137
|
+
* An index in this array is thus a window index modulo 32K.
|
138
|
+
*/
|
139
|
+
|
140
|
+
Posf *head; /* Heads of the hash chains or NIL. */
|
141
|
+
|
142
|
+
uInt ins_h; /* hash index of string to be inserted */
|
143
|
+
uInt hash_size; /* number of elements in hash table */
|
144
|
+
uInt hash_bits; /* log2(hash_size) */
|
145
|
+
uInt hash_mask; /* hash_size-1 */
|
146
|
+
|
147
|
+
uInt hash_shift;
|
148
|
+
/* Number of bits by which ins_h must be shifted at each input
|
149
|
+
* step. It must be such that after MIN_MATCH steps, the oldest
|
150
|
+
* byte no longer takes part in the hash key, that is:
|
151
|
+
* hash_shift * MIN_MATCH >= hash_bits
|
152
|
+
*/
|
153
|
+
|
154
|
+
long block_start;
|
155
|
+
/* Window position at the beginning of the current output block. Gets
|
156
|
+
* negative when the window is moved backwards.
|
157
|
+
*/
|
158
|
+
|
159
|
+
uInt match_length; /* length of best match */
|
160
|
+
IPos prev_match; /* previous match */
|
161
|
+
int match_available; /* set if previous match exists */
|
162
|
+
uInt strstart; /* start of string to insert */
|
163
|
+
uInt match_start; /* start of matching string */
|
164
|
+
uInt lookahead; /* number of valid bytes ahead in window */
|
165
|
+
|
166
|
+
uInt prev_length;
|
167
|
+
/* Length of the best match at previous step. Matches not greater than this
|
168
|
+
* are discarded. This is used in the lazy match evaluation.
|
169
|
+
*/
|
170
|
+
|
171
|
+
uInt max_chain_length;
|
172
|
+
/* To speed up deflation, hash chains are never searched beyond this
|
173
|
+
* length. A higher limit improves compression ratio but degrades the
|
174
|
+
* speed.
|
175
|
+
*/
|
176
|
+
|
177
|
+
uInt max_lazy_match;
|
178
|
+
/* Attempt to find a better match only when the current match is strictly
|
179
|
+
* smaller than this value. This mechanism is used only for compression
|
180
|
+
* levels >= 4.
|
181
|
+
*/
|
182
|
+
# define max_insert_length max_lazy_match
|
183
|
+
/* Insert new strings in the hash table only if the match length is not
|
184
|
+
* greater than this length. This saves time but degrades compression.
|
185
|
+
* max_insert_length is used only for compression levels <= 3.
|
186
|
+
*/
|
187
|
+
|
188
|
+
int level; /* compression level (1..9) */
|
189
|
+
int strategy; /* favor or force Huffman coding*/
|
190
|
+
|
191
|
+
uInt good_match;
|
192
|
+
/* Use a faster search when the previous match is longer than this */
|
193
|
+
|
194
|
+
int nice_match; /* Stop searching when current match exceeds this */
|
195
|
+
|
196
|
+
/* used by trees.c: */
|
197
|
+
/* Didn't use ct_data typedef below to suppress compiler warning */
|
198
|
+
struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
|
199
|
+
struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
|
200
|
+
struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
|
201
|
+
|
202
|
+
struct tree_desc_s l_desc; /* desc. for literal tree */
|
203
|
+
struct tree_desc_s d_desc; /* desc. for distance tree */
|
204
|
+
struct tree_desc_s bl_desc; /* desc. for bit length tree */
|
205
|
+
|
206
|
+
ush bl_count[MAX_BITS+1];
|
207
|
+
/* number of codes at each bit length for an optimal tree */
|
208
|
+
|
209
|
+
int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
|
210
|
+
int heap_len; /* number of elements in the heap */
|
211
|
+
int heap_max; /* element of largest frequency */
|
212
|
+
/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
|
213
|
+
* The same heap array is used to build all trees.
|
214
|
+
*/
|
215
|
+
|
216
|
+
uch depth[2*L_CODES+1];
|
217
|
+
/* Depth of each subtree used as tie breaker for trees of equal frequency
|
218
|
+
*/
|
219
|
+
|
220
|
+
uchf *l_buf; /* buffer for literals or lengths */
|
221
|
+
|
222
|
+
uInt lit_bufsize;
|
223
|
+
/* Size of match buffer for literals/lengths. There are 4 reasons for
|
224
|
+
* limiting lit_bufsize to 64K:
|
225
|
+
* - frequencies can be kept in 16 bit counters
|
226
|
+
* - if compression is not successful for the first block, all input
|
227
|
+
* data is still in the window so we can still emit a stored block even
|
228
|
+
* when input comes from standard input. (This can also be done for
|
229
|
+
* all blocks if lit_bufsize is not greater than 32K.)
|
230
|
+
* - if compression is not successful for a file smaller than 64K, we can
|
231
|
+
* even emit a stored file instead of a stored block (saving 5 bytes).
|
232
|
+
* This is applicable only for zip (not gzip or zlib).
|
233
|
+
* - creating new Huffman trees less frequently may not provide fast
|
234
|
+
* adaptation to changes in the input data statistics. (Take for
|
235
|
+
* example a binary file with poorly compressible code followed by
|
236
|
+
* a highly compressible string table.) Smaller buffer sizes give
|
237
|
+
* fast adaptation but have of course the overhead of transmitting
|
238
|
+
* trees more frequently.
|
239
|
+
* - I can't count above 4
|
240
|
+
*/
|
241
|
+
|
242
|
+
uInt last_lit; /* running index in l_buf */
|
243
|
+
|
244
|
+
ushf *d_buf;
|
245
|
+
/* Buffer for distances. To simplify the code, d_buf and l_buf have
|
246
|
+
* the same number of elements. To use different lengths, an extra flag
|
247
|
+
* array would be necessary.
|
248
|
+
*/
|
249
|
+
|
250
|
+
ulg opt_len; /* bit length of current block with optimal trees */
|
251
|
+
ulg static_len; /* bit length of current block with static trees */
|
252
|
+
uInt matches; /* number of string matches in current block */
|
253
|
+
uInt insert; /* bytes at end of window left to insert */
|
254
|
+
|
255
|
+
#ifdef ZLIB_DEBUG
|
256
|
+
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
|
257
|
+
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
|
258
|
+
#endif
|
259
|
+
|
260
|
+
ush bi_buf;
|
261
|
+
/* Output buffer. bits are inserted starting at the bottom (least
|
262
|
+
* significant bits).
|
263
|
+
*/
|
264
|
+
int bi_valid;
|
265
|
+
/* Number of valid bits in bi_buf. All bits above the last valid bit
|
266
|
+
* are always zero.
|
267
|
+
*/
|
268
|
+
|
269
|
+
ulg high_water;
|
270
|
+
/* High water mark offset in window for initialized bytes -- bytes above
|
271
|
+
* this are set to zero in order to avoid memory check warnings when
|
272
|
+
* longest match routines access bytes past the input. This is then
|
273
|
+
* updated to the new high water mark.
|
274
|
+
*/
|
275
|
+
|
276
|
+
} FAR deflate_state;
|
277
|
+
|
278
|
+
/* Output a byte on the stream.
|
279
|
+
* IN assertion: there is enough room in pending_buf.
|
280
|
+
*/
|
281
|
+
#define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
|
282
|
+
|
283
|
+
|
284
|
+
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
|
285
|
+
/* Minimum amount of lookahead, except at the end of the input file.
|
286
|
+
* See deflate.c for comments about the MIN_MATCH+1.
|
287
|
+
*/
|
288
|
+
|
289
|
+
#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
|
290
|
+
/* In order to simplify the code, particularly on 16 bit machines, match
|
291
|
+
* distances are limited to MAX_DIST instead of WSIZE.
|
292
|
+
*/
|
293
|
+
|
294
|
+
#define WIN_INIT MAX_MATCH
|
295
|
+
/* Number of bytes after end of data in window to initialize in order to avoid
|
296
|
+
memory checker errors from longest match routines */
|
297
|
+
|
298
|
+
/* in trees.c */
|
299
|
+
void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
|
300
|
+
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
|
301
|
+
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
|
302
|
+
ulg stored_len, int last));
|
303
|
+
void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
|
304
|
+
void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
|
305
|
+
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
|
306
|
+
ulg stored_len, int last));
|
307
|
+
|
308
|
+
#define d_code(dist) \
|
309
|
+
((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
|
310
|
+
/* Mapping from a distance to a distance code. dist is the distance - 1 and
|
311
|
+
* must not have side effects. _dist_code[256] and _dist_code[257] are never
|
312
|
+
* used.
|
313
|
+
*/
|
314
|
+
|
315
|
+
#ifndef ZLIB_DEBUG
|
316
|
+
/* Inline versions of _tr_tally for speed: */
|
317
|
+
|
318
|
+
#if defined(GEN_TREES_H) || !defined(STDC)
|
319
|
+
extern uch ZLIB_INTERNAL _length_code[];
|
320
|
+
extern uch ZLIB_INTERNAL _dist_code[];
|
321
|
+
#else
|
322
|
+
extern const uch ZLIB_INTERNAL _length_code[];
|
323
|
+
extern const uch ZLIB_INTERNAL _dist_code[];
|
324
|
+
#endif
|
325
|
+
|
326
|
+
# define _tr_tally_lit(s, c, flush) \
|
327
|
+
{ uch cc = (c); \
|
328
|
+
s->d_buf[s->last_lit] = 0; \
|
329
|
+
s->l_buf[s->last_lit++] = cc; \
|
330
|
+
s->dyn_ltree[cc].Freq++; \
|
331
|
+
flush = (s->last_lit == s->lit_bufsize-1); \
|
332
|
+
}
|
333
|
+
# define _tr_tally_dist(s, distance, length, flush) \
|
334
|
+
{ uch len = (uch)(length); \
|
335
|
+
ush dist = (ush)(distance); \
|
336
|
+
s->d_buf[s->last_lit] = dist; \
|
337
|
+
s->l_buf[s->last_lit++] = len; \
|
338
|
+
dist--; \
|
339
|
+
s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
|
340
|
+
s->dyn_dtree[d_code(dist)].Freq++; \
|
341
|
+
flush = (s->last_lit == s->lit_bufsize-1); \
|
342
|
+
}
|
343
|
+
#else
|
344
|
+
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
|
345
|
+
# define _tr_tally_dist(s, distance, length, flush) \
|
346
|
+
flush = _tr_tally(s, distance, length)
|
347
|
+
#endif
|
348
|
+
|
349
|
+
#endif /* DEFLATE_H */
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/* gzclose.c -- zlib gzclose() function
|
2
|
+
* Copyright (C) 2004, 2010 Mark Adler
|
3
|
+
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
|
+
*/
|
5
|
+
|
6
|
+
#include "gzguts.h"
|
7
|
+
|
8
|
+
/* gzclose() is in a separate file so that it is linked in only if it is used.
|
9
|
+
That way the other gzclose functions can be used instead to avoid linking in
|
10
|
+
unneeded compression or decompression routines. */
|
11
|
+
int ZEXPORT gzclose(file)
|
12
|
+
gzFile file;
|
13
|
+
{
|
14
|
+
#ifndef NO_GZCOMPRESS
|
15
|
+
gz_statep state;
|
16
|
+
|
17
|
+
if (file == NULL)
|
18
|
+
return Z_STREAM_ERROR;
|
19
|
+
state = (gz_statep)file;
|
20
|
+
|
21
|
+
return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
|
22
|
+
#else
|
23
|
+
return gzclose_r(file);
|
24
|
+
#endif
|
25
|
+
}
|
@@ -0,0 +1,218 @@
|
|
1
|
+
/* gzguts.h -- zlib internal header definitions for gz* operations
|
2
|
+
* Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler
|
3
|
+
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifdef _LARGEFILE64_SOURCE
|
7
|
+
# ifndef _LARGEFILE_SOURCE
|
8
|
+
# define _LARGEFILE_SOURCE 1
|
9
|
+
# endif
|
10
|
+
# ifdef _FILE_OFFSET_BITS
|
11
|
+
# undef _FILE_OFFSET_BITS
|
12
|
+
# endif
|
13
|
+
#endif
|
14
|
+
|
15
|
+
#ifdef HAVE_HIDDEN
|
16
|
+
# define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
|
17
|
+
#else
|
18
|
+
# define ZLIB_INTERNAL
|
19
|
+
#endif
|
20
|
+
|
21
|
+
#include <stdio.h>
|
22
|
+
#include "zlib.h"
|
23
|
+
#ifdef STDC
|
24
|
+
# include <string.h>
|
25
|
+
# include <stdlib.h>
|
26
|
+
# include <limits.h>
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#ifndef _POSIX_SOURCE
|
30
|
+
# define _POSIX_SOURCE
|
31
|
+
#endif
|
32
|
+
#include <fcntl.h>
|
33
|
+
|
34
|
+
#ifdef _WIN32
|
35
|
+
# include <stddef.h>
|
36
|
+
#endif
|
37
|
+
|
38
|
+
#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
|
39
|
+
# include <io.h>
|
40
|
+
#endif
|
41
|
+
|
42
|
+
#if defined(_WIN32) || defined(__CYGWIN__)
|
43
|
+
# define WIDECHAR
|
44
|
+
#endif
|
45
|
+
|
46
|
+
#ifdef WINAPI_FAMILY
|
47
|
+
# define open _open
|
48
|
+
# define read _read
|
49
|
+
# define write _write
|
50
|
+
# define close _close
|
51
|
+
#endif
|
52
|
+
|
53
|
+
#ifdef NO_DEFLATE /* for compatibility with old definition */
|
54
|
+
# define NO_GZCOMPRESS
|
55
|
+
#endif
|
56
|
+
|
57
|
+
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
|
58
|
+
# ifndef HAVE_VSNPRINTF
|
59
|
+
# define HAVE_VSNPRINTF
|
60
|
+
# endif
|
61
|
+
#endif
|
62
|
+
|
63
|
+
#if defined(__CYGWIN__)
|
64
|
+
# ifndef HAVE_VSNPRINTF
|
65
|
+
# define HAVE_VSNPRINTF
|
66
|
+
# endif
|
67
|
+
#endif
|
68
|
+
|
69
|
+
#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410)
|
70
|
+
# ifndef HAVE_VSNPRINTF
|
71
|
+
# define HAVE_VSNPRINTF
|
72
|
+
# endif
|
73
|
+
#endif
|
74
|
+
|
75
|
+
#ifndef HAVE_VSNPRINTF
|
76
|
+
# ifdef MSDOS
|
77
|
+
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
78
|
+
but for now we just assume it doesn't. */
|
79
|
+
# define NO_vsnprintf
|
80
|
+
# endif
|
81
|
+
# ifdef __TURBOC__
|
82
|
+
# define NO_vsnprintf
|
83
|
+
# endif
|
84
|
+
# ifdef WIN32
|
85
|
+
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
86
|
+
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
87
|
+
# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
|
88
|
+
# define vsnprintf _vsnprintf
|
89
|
+
# endif
|
90
|
+
# endif
|
91
|
+
# endif
|
92
|
+
# ifdef __SASC
|
93
|
+
# define NO_vsnprintf
|
94
|
+
# endif
|
95
|
+
# ifdef VMS
|
96
|
+
# define NO_vsnprintf
|
97
|
+
# endif
|
98
|
+
# ifdef __OS400__
|
99
|
+
# define NO_vsnprintf
|
100
|
+
# endif
|
101
|
+
# ifdef __MVS__
|
102
|
+
# define NO_vsnprintf
|
103
|
+
# endif
|
104
|
+
#endif
|
105
|
+
|
106
|
+
/* unlike snprintf (which is required in C99), _snprintf does not guarantee
|
107
|
+
null termination of the result -- however this is only used in gzlib.c where
|
108
|
+
the result is assured to fit in the space provided */
|
109
|
+
#if defined(_MSC_VER) && _MSC_VER < 1900
|
110
|
+
# define snprintf _snprintf
|
111
|
+
#endif
|
112
|
+
|
113
|
+
#ifndef local
|
114
|
+
# define local static
|
115
|
+
#endif
|
116
|
+
/* since "static" is used to mean two completely different things in C, we
|
117
|
+
define "local" for the non-static meaning of "static", for readability
|
118
|
+
(compile with -Dlocal if your debugger can't find static symbols) */
|
119
|
+
|
120
|
+
/* gz* functions always use library allocation functions */
|
121
|
+
#ifndef STDC
|
122
|
+
extern voidp malloc OF((uInt size));
|
123
|
+
extern void free OF((voidpf ptr));
|
124
|
+
#endif
|
125
|
+
|
126
|
+
/* get errno and strerror definition */
|
127
|
+
#if defined UNDER_CE
|
128
|
+
# include <windows.h>
|
129
|
+
# define zstrerror() gz_strwinerror((DWORD)GetLastError())
|
130
|
+
#else
|
131
|
+
# ifndef NO_STRERROR
|
132
|
+
# include <errno.h>
|
133
|
+
# define zstrerror() strerror(errno)
|
134
|
+
# else
|
135
|
+
# define zstrerror() "stdio error (consult errno)"
|
136
|
+
# endif
|
137
|
+
#endif
|
138
|
+
|
139
|
+
/* provide prototypes for these when building zlib without LFS */
|
140
|
+
#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
|
141
|
+
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
|
142
|
+
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
|
143
|
+
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
|
144
|
+
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
|
145
|
+
#endif
|
146
|
+
|
147
|
+
/* default memLevel */
|
148
|
+
#if MAX_MEM_LEVEL >= 8
|
149
|
+
# define DEF_MEM_LEVEL 8
|
150
|
+
#else
|
151
|
+
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
152
|
+
#endif
|
153
|
+
|
154
|
+
/* default i/o buffer size -- double this for output when reading (this and
|
155
|
+
twice this must be able to fit in an unsigned type) */
|
156
|
+
#define GZBUFSIZE 8192
|
157
|
+
|
158
|
+
/* gzip modes, also provide a little integrity check on the passed structure */
|
159
|
+
#define GZ_NONE 0
|
160
|
+
#define GZ_READ 7247
|
161
|
+
#define GZ_WRITE 31153
|
162
|
+
#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
|
163
|
+
|
164
|
+
/* values for gz_state how */
|
165
|
+
#define LOOK 0 /* look for a gzip header */
|
166
|
+
#define COPY 1 /* copy input directly */
|
167
|
+
#define GZIP 2 /* decompress a gzip stream */
|
168
|
+
|
169
|
+
/* internal gzip file state data structure */
|
170
|
+
typedef struct {
|
171
|
+
/* exposed contents for gzgetc() macro */
|
172
|
+
struct gzFile_s x; /* "x" for exposed */
|
173
|
+
/* x.have: number of bytes available at x.next */
|
174
|
+
/* x.next: next output data to deliver or write */
|
175
|
+
/* x.pos: current position in uncompressed data */
|
176
|
+
/* used for both reading and writing */
|
177
|
+
int mode; /* see gzip modes above */
|
178
|
+
int fd; /* file descriptor */
|
179
|
+
char *path; /* path or fd for error messages */
|
180
|
+
unsigned size; /* buffer size, zero if not allocated yet */
|
181
|
+
unsigned want; /* requested buffer size, default is GZBUFSIZE */
|
182
|
+
unsigned char *in; /* input buffer (double-sized when writing) */
|
183
|
+
unsigned char *out; /* output buffer (double-sized when reading) */
|
184
|
+
int direct; /* 0 if processing gzip, 1 if transparent */
|
185
|
+
/* just for reading */
|
186
|
+
int how; /* 0: get header, 1: copy, 2: decompress */
|
187
|
+
z_off64_t start; /* where the gzip data started, for rewinding */
|
188
|
+
int eof; /* true if end of input file reached */
|
189
|
+
int past; /* true if read requested past end */
|
190
|
+
/* just for writing */
|
191
|
+
int level; /* compression level */
|
192
|
+
int strategy; /* compression strategy */
|
193
|
+
/* seek request */
|
194
|
+
z_off64_t skip; /* amount to skip (already rewound if backwards) */
|
195
|
+
int seek; /* true if seek request pending */
|
196
|
+
/* error information */
|
197
|
+
int err; /* error code */
|
198
|
+
char *msg; /* error message */
|
199
|
+
/* zlib inflate or deflate stream */
|
200
|
+
z_stream strm; /* stream structure in-place (not a pointer) */
|
201
|
+
} gz_state;
|
202
|
+
typedef gz_state FAR *gz_statep;
|
203
|
+
|
204
|
+
/* shared functions */
|
205
|
+
void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
|
206
|
+
#if defined UNDER_CE
|
207
|
+
char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
|
208
|
+
#endif
|
209
|
+
|
210
|
+
/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
|
211
|
+
value -- needed when comparing unsigned to z_off64_t, which is signed
|
212
|
+
(possible z_off64_t types off_t, off64_t, and long are all signed) */
|
213
|
+
#ifdef INT_MAX
|
214
|
+
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
|
215
|
+
#else
|
216
|
+
unsigned ZLIB_INTERNAL gz_intmax OF((void));
|
217
|
+
# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
|
218
|
+
#endif
|