zlib-streams 1.0.7 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/Makefile +21 -8
  2. package/dist/zlib-streams-dev.wasm +0 -0
  3. package/dist/zlib-streams.js +135 -62
  4. package/dist/zlib-streams.wasm +0 -0
  5. package/package.json +2 -2
  6. package/src/README.md +61 -1
  7. package/src/chunkcopy.h +565 -0
  8. package/src/compare256.h +56 -0
  9. package/src/cpu_features.h +22 -0
  10. package/src/deflate.c +2349 -0
  11. package/src/deflate.h +420 -0
  12. package/src/deflate_crc32.c +22 -0
  13. package/src/inffast.h +26 -0
  14. package/src/{inffast.c → inffast_chunk.c} +127 -71
  15. package/src/inffast_chunk.h +42 -0
  16. package/src/inflate.c +69 -33
  17. package/src/insert_string.h +80 -0
  18. package/src/wasm/api/zlib-streams.js +135 -62
  19. package/build/debug/src/inffast.d +0 -8
  20. package/build/debug/src/inffast.o +0 -0
  21. package/build/debug/src/inflate.d +0 -8
  22. package/build/debug/src/inflate.o +0 -0
  23. package/build/debug/src/inftrees.d +0 -6
  24. package/build/debug/src/inftrees.o +0 -0
  25. package/build/debug/src/zlib/adler32.d +0 -5
  26. package/build/debug/src/zlib/adler32.o +0 -0
  27. package/build/debug/src/zlib/contrib/infback9/infback9.d +0 -13
  28. package/build/debug/src/zlib/contrib/infback9/infback9.o +0 -0
  29. package/build/debug/src/zlib/contrib/infback9/inftree9.d +0 -7
  30. package/build/debug/src/zlib/contrib/infback9/inftree9.o +0 -0
  31. package/build/debug/src/zlib/crc32.d +0 -6
  32. package/build/debug/src/zlib/crc32.o +0 -0
  33. package/build/debug/src/zlib/trees.d +0 -7
  34. package/build/debug/src/zlib/trees.o +0 -0
  35. package/build/debug/src/zlib/zutil.d +0 -6
  36. package/build/debug/src/zlib/zutil.o +0 -0
  37. package/tmp/all_runs/payload_decompress_nowindow_debug__100k_lines.deflate64.log +0 -34
  38. package/tmp/all_runs/payload_decompress_nowindow_debug__100k_lines.deflate64.out +0 -100000
  39. package/tmp/all_runs/payload_decompress_nowindow_debug__10k_lines.deflate64.log +0 -2
  40. package/tmp/all_runs/payload_decompress_nowindow_debug__10k_lines.deflate64.out +0 -10000
  41. package/tmp/all_runs/payload_decompress_nowindow_debug__payload_63k.deflate64.log +0 -1
  42. package/tmp/all_runs/payload_decompress_nowindow_debug__payload_63k.deflate64.out +0 -0
  43. package/tmp/all_runs/payload_decompress_nowindow_debug__payload_64k.deflate64.log +0 -1
  44. package/tmp/all_runs/payload_decompress_nowindow_debug__payload_64k.deflate64.out +0 -0
  45. package/tmp/all_runs/payload_decompress_nowindow_debug__payload_65k.deflate64.log +0 -2
  46. package/tmp/all_runs/payload_decompress_nowindow_debug__payload_65k.deflate64.out +0 -0
  47. package/tmp/all_runs/payload_decompress_nowindow_debug__rand_block_gap.deflate64.log +0 -1
  48. package/tmp/all_runs/payload_decompress_nowindow_debug__rand_block_gap.deflate64.out +0 -0
  49. package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_63k.deflate64.log +0 -1
  50. package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_63k.deflate64.out +0 -0
  51. package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_64k.deflate64.log +0 -1
  52. package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_64k.deflate64.out +0 -0
  53. package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_65k.deflate64.log +0 -2
  54. package/tmp/all_runs/payload_decompress_nowindow_debug__repeat_65k.deflate64.out +0 -0
  55. package/tmp/all_runs/payload_decompress_nowindow_debug__zeros_100k.deflate64.log +0 -2
  56. package/tmp/all_runs/payload_decompress_nowindow_debug__zeros_100k.deflate64.out +0 -0
  57. package/tmp/all_runs/payload_decompress_ref_debug__100k_lines.deflate64.log +0 -1
  58. package/tmp/all_runs/payload_decompress_ref_debug__100k_lines.deflate64.out +0 -100000
  59. package/tmp/all_runs/payload_decompress_ref_debug__10k_lines.deflate64.log +0 -1
  60. package/tmp/all_runs/payload_decompress_ref_debug__10k_lines.deflate64.out +0 -10000
  61. package/tmp/all_runs/payload_decompress_ref_debug__payload_63k.deflate64.log +0 -1
  62. package/tmp/all_runs/payload_decompress_ref_debug__payload_63k.deflate64.out +0 -0
  63. package/tmp/all_runs/payload_decompress_ref_debug__payload_64k.deflate64.log +0 -1
  64. package/tmp/all_runs/payload_decompress_ref_debug__payload_64k.deflate64.out +0 -0
  65. package/tmp/all_runs/payload_decompress_ref_debug__payload_65k.deflate64.log +0 -1
  66. package/tmp/all_runs/payload_decompress_ref_debug__payload_65k.deflate64.out +0 -0
  67. package/tmp/all_runs/payload_decompress_ref_debug__rand_block_gap.deflate64.log +0 -1
  68. package/tmp/all_runs/payload_decompress_ref_debug__rand_block_gap.deflate64.out +0 -0
  69. package/tmp/all_runs/payload_decompress_ref_debug__repeat_63k.deflate64.log +0 -1
  70. package/tmp/all_runs/payload_decompress_ref_debug__repeat_63k.deflate64.out +0 -0
  71. package/tmp/all_runs/payload_decompress_ref_debug__repeat_64k.deflate64.log +0 -1
  72. package/tmp/all_runs/payload_decompress_ref_debug__repeat_64k.deflate64.out +0 -0
  73. package/tmp/all_runs/payload_decompress_ref_debug__repeat_65k.deflate64.log +0 -1
  74. package/tmp/all_runs/payload_decompress_ref_debug__repeat_65k.deflate64.out +0 -0
  75. package/tmp/all_runs/payload_decompress_ref_debug__zeros_100k.deflate64.log +0 -1
  76. package/tmp/all_runs/payload_decompress_ref_debug__zeros_100k.deflate64.out +0 -0
  77. package/tmp/all_runs/payload_decompress_test_debug__100k_lines.deflate64.log +0 -34
  78. package/tmp/all_runs/payload_decompress_test_debug__100k_lines.deflate64.out +0 -100000
  79. package/tmp/all_runs/payload_decompress_test_debug__10k_lines.deflate64.log +0 -2
  80. package/tmp/all_runs/payload_decompress_test_debug__10k_lines.deflate64.out +0 -10000
  81. package/tmp/all_runs/payload_decompress_test_debug__payload_63k.deflate64.log +0 -1
  82. package/tmp/all_runs/payload_decompress_test_debug__payload_63k.deflate64.out +0 -0
  83. package/tmp/all_runs/payload_decompress_test_debug__payload_64k.deflate64.log +0 -1
  84. package/tmp/all_runs/payload_decompress_test_debug__payload_64k.deflate64.out +0 -0
  85. package/tmp/all_runs/payload_decompress_test_debug__payload_65k.deflate64.log +0 -2
  86. package/tmp/all_runs/payload_decompress_test_debug__payload_65k.deflate64.out +0 -0
  87. package/tmp/all_runs/payload_decompress_test_debug__rand_block_gap.deflate64.log +0 -1
  88. package/tmp/all_runs/payload_decompress_test_debug__rand_block_gap.deflate64.out +0 -0
  89. package/tmp/all_runs/payload_decompress_test_debug__repeat_63k.deflate64.log +0 -1
  90. package/tmp/all_runs/payload_decompress_test_debug__repeat_63k.deflate64.out +0 -0
  91. package/tmp/all_runs/payload_decompress_test_debug__repeat_64k.deflate64.log +0 -1
  92. package/tmp/all_runs/payload_decompress_test_debug__repeat_64k.deflate64.out +0 -0
  93. package/tmp/all_runs/payload_decompress_test_debug__repeat_65k.deflate64.log +0 -2
  94. package/tmp/all_runs/payload_decompress_test_debug__repeat_65k.deflate64.out +0 -0
  95. package/tmp/all_runs/payload_decompress_test_debug__zeros_100k.deflate64.log +0 -2
  96. package/tmp/all_runs/payload_decompress_test_debug__zeros_100k.deflate64.out +0 -0
  97. package/tmp/all_runs/wasm__100k_lines.deflate64.out +0 -100000
  98. package/tmp/all_runs/wasm__10k_lines.deflate64.out +0 -10000
  99. package/tmp/all_runs/wasm__payload_63k.deflate64.out +0 -0
  100. package/tmp/all_runs/wasm__payload_64k.deflate64.out +0 -0
  101. package/tmp/all_runs/wasm__payload_65k.deflate64.out +0 -0
  102. package/tmp/all_runs/wasm__rand_block_gap.deflate64.out +0 -0
  103. package/tmp/all_runs/wasm__repeat_63k.deflate64.out +0 -0
  104. package/tmp/all_runs/wasm__repeat_64k.deflate64.out +0 -0
  105. package/tmp/all_runs/wasm__repeat_65k.deflate64.out +0 -0
  106. package/tmp/all_runs/wasm__zeros_100k.deflate64.out +0 -0
  107. package/tmp/diagnose/diagnose_stream_mem.json +0 -4202
package/src/deflate.h ADDED
@@ -0,0 +1,420 @@
1
+ /* deflate.h -- internal compression state
2
+ * Copyright (C) 1995-2026 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
+ #if defined(DEFLATE_CHUNK_WRITE_64LE)
17
+ #include <stdint.h>
18
+ #endif
19
+
20
+ #include "zutil.h"
21
+
22
+ /* Chromium's deflate.c calls zmemcpy/zmemzero on deflate_state, Posf and
23
+ z_streamp pointers, because its own zutil.h declares them as taking void*.
24
+ This build keeps madler's zutil.h, where they take Bytef*, so cast at the
25
+ call sites. The inner name is not re-expanded, so these stay function calls. */
26
+ #define zmemcpy(dest, source, len) zmemcpy((Bytef *)(dest), (const Bytef *)(source), (len))
27
+ #define zmemzero(dest, len) zmemzero((Bytef *)(dest), (len))
28
+
29
+ /* define NO_GZIP when compiling if you want to disable gzip header and
30
+ trailer creation by deflate(). NO_GZIP would be used to avoid linking in
31
+ the crc code when it is not needed. For shared libraries, gzip encoding
32
+ should be left enabled. */
33
+ #ifndef NO_GZIP
34
+ # define GZIP
35
+ #endif
36
+
37
+ /* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
38
+ the cost of a larger memory footprint */
39
+ /* #define LIT_MEM */
40
+
41
+ /* ===========================================================================
42
+ * Internal compression state.
43
+ */
44
+
45
+ #define LENGTH_CODES 29
46
+ /* number of length codes, not counting the special END_BLOCK code */
47
+
48
+ #define LITERALS 256
49
+ /* number of literal bytes 0..255 */
50
+
51
+ #define L_CODES (LITERALS+1+LENGTH_CODES)
52
+ /* number of Literal or Length codes, including the END_BLOCK code */
53
+
54
+ #define D_CODES 30
55
+ /* number of distance codes */
56
+
57
+ #define BL_CODES 19
58
+ /* number of codes used to transfer the bit lengths */
59
+
60
+ #define HEAP_SIZE (2*L_CODES+1)
61
+ /* maximum heap size */
62
+
63
+ #define MAX_BITS 15
64
+ /* All codes must not exceed MAX_BITS bits */
65
+
66
+ #if defined(DEFLATE_CHUNK_WRITE_64LE)
67
+ #define Buf_size 64
68
+ #else
69
+ #define Buf_size 16
70
+ #endif
71
+ /* size of bit buffer in bi_buf */
72
+
73
+ #define INIT_STATE 42 /* zlib header -> BUSY_STATE */
74
+ #ifdef GZIP
75
+ # define GZIP_STATE 57 /* gzip header -> BUSY_STATE | EXTRA_STATE */
76
+ #endif
77
+ #define EXTRA_STATE 69 /* gzip extra block -> NAME_STATE */
78
+ #define NAME_STATE 73 /* gzip file name -> COMMENT_STATE */
79
+ #define COMMENT_STATE 91 /* gzip comment -> HCRC_STATE */
80
+ #define HCRC_STATE 103 /* gzip header CRC -> BUSY_STATE */
81
+ #define BUSY_STATE 113 /* deflate -> FINISH_STATE */
82
+ #define FINISH_STATE 666 /* stream complete */
83
+ /* Stream status */
84
+
85
+
86
+ /* Data structure describing a single value and its code string. */
87
+ typedef struct ct_data_s {
88
+ union {
89
+ ush freq; /* frequency count */
90
+ ush code; /* bit string */
91
+ } fc;
92
+ union {
93
+ ush dad; /* father node in Huffman tree */
94
+ ush len; /* length of bit string */
95
+ } dl;
96
+ } FAR ct_data;
97
+
98
+ #define Freq fc.freq
99
+ #define Code fc.code
100
+ #define Dad dl.dad
101
+ #define Len dl.len
102
+
103
+ typedef struct static_tree_desc_s static_tree_desc;
104
+
105
+ typedef struct tree_desc_s {
106
+ ct_data *dyn_tree; /* the dynamic tree */
107
+ int max_code; /* largest code with non zero frequency */
108
+ const static_tree_desc *stat_desc; /* the corresponding static tree */
109
+ } FAR tree_desc;
110
+
111
+ typedef ush Pos;
112
+ typedef Pos FAR Posf;
113
+ typedef unsigned IPos;
114
+
115
+ /* A Pos is an index in the character window. We use short instead of int to
116
+ * save space in the various tables. IPos is used only for parameter passing.
117
+ */
118
+
119
+ typedef struct internal_state {
120
+ z_streamp strm; /* pointer back to this zlib stream */
121
+ int status; /* as the name implies */
122
+ Bytef *pending_buf; /* output still pending */
123
+ ulg pending_buf_size; /* size of pending_buf */
124
+ Bytef *pending_out; /* next pending byte to output to the stream */
125
+ ulg pending; /* nb of bytes in the pending buffer */
126
+ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
127
+ gz_headerp gzhead; /* gzip header information to write */
128
+ ulg gzindex; /* where in extra, name, or comment */
129
+ Byte method; /* can only be DEFLATED */
130
+ int last_flush; /* value of flush param for previous deflate call */
131
+ unsigned crc0[4 * 5];
132
+ /* used by deflate.c: */
133
+
134
+ uInt w_size; /* LZ77 window size (32K by default) */
135
+ uInt w_bits; /* log2(w_size) (8..16) */
136
+ uInt w_mask; /* w_size - 1 */
137
+
138
+ Bytef *window;
139
+ /* Sliding window. Input bytes are read into the second half of the window,
140
+ * and move to the first half later to keep a dictionary of at least wSize
141
+ * bytes. With this organization, matches are limited to a distance of
142
+ * wSize-MAX_MATCH bytes, but this ensures that IO is always
143
+ * performed with a length multiple of the block size. Also, it limits
144
+ * the window size to 64K, which is quite useful on MSDOS.
145
+ * To do: use the user input buffer as sliding window.
146
+ */
147
+
148
+ ulg window_size;
149
+ /* Actual size of window: 2*wSize, except when the user input buffer
150
+ * is directly used as sliding window.
151
+ */
152
+
153
+ Posf *prev;
154
+ /* Link to older string with same hash index. To limit the size of this
155
+ * array to 64K, this link is maintained only for the last 32K strings.
156
+ * An index in this array is thus a window index modulo 32K.
157
+ */
158
+
159
+ Posf *head; /* Heads of the hash chains or NIL. */
160
+
161
+ uInt ins_h; /* hash index of string to be inserted */
162
+ uInt hash_size; /* number of elements in hash table */
163
+ uInt hash_bits; /* log2(hash_size) */
164
+ uInt hash_mask; /* hash_size-1 */
165
+
166
+ uInt hash_shift;
167
+ /* Number of bits by which ins_h must be shifted at each input
168
+ * step. It must be such that after MIN_MATCH steps, the oldest
169
+ * byte no longer takes part in the hash key, that is:
170
+ * hash_shift * MIN_MATCH >= hash_bits
171
+ */
172
+
173
+ long block_start;
174
+ /* Window position at the beginning of the current output block. Gets
175
+ * negative when the window is moved backwards.
176
+ */
177
+
178
+ uInt match_length; /* length of best match */
179
+ IPos prev_match; /* previous match */
180
+ int match_available; /* set if previous match exists */
181
+ uInt strstart; /* start of string to insert */
182
+ uInt match_start; /* start of matching string */
183
+ uInt lookahead; /* number of valid bytes ahead in window */
184
+
185
+ uInt prev_length;
186
+ /* Length of the best match at previous step. Matches not greater than this
187
+ * are discarded. This is used in the lazy match evaluation.
188
+ */
189
+
190
+ uInt max_chain_length;
191
+ /* To speed up deflation, hash chains are never searched beyond this
192
+ * length. A higher limit improves compression ratio but degrades the
193
+ * speed.
194
+ */
195
+
196
+ uInt max_lazy_match;
197
+ /* Attempt to find a better match only when the current match is strictly
198
+ * smaller than this value. This mechanism is used only for compression
199
+ * levels >= 4.
200
+ */
201
+ # define max_insert_length max_lazy_match
202
+ /* Insert new strings in the hash table only if the match length is not
203
+ * greater than this length. This saves time but degrades compression.
204
+ * max_insert_length is used only for compression levels <= 3.
205
+ */
206
+
207
+ int level; /* compression level (1..9) */
208
+ int strategy; /* favor or force Huffman coding*/
209
+
210
+ uInt good_match;
211
+ /* Use a faster search when the previous match is longer than this */
212
+
213
+ int nice_match; /* Stop searching when current match exceeds this */
214
+
215
+ /* used by trees.c: */
216
+ /* Didn't use ct_data typedef below to suppress compiler warning */
217
+ struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
218
+ struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
219
+ struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
220
+
221
+ struct tree_desc_s l_desc; /* desc. for literal tree */
222
+ struct tree_desc_s d_desc; /* desc. for distance tree */
223
+ struct tree_desc_s bl_desc; /* desc. for bit length tree */
224
+
225
+ ush bl_count[MAX_BITS+1];
226
+ /* number of codes at each bit length for an optimal tree */
227
+
228
+ int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
229
+ int heap_len; /* number of elements in the heap */
230
+ int heap_max; /* element of largest frequency */
231
+ /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
232
+ * The same heap array is used to build all trees.
233
+ */
234
+
235
+ uch depth[2*L_CODES+1];
236
+ /* Depth of each subtree used as tie breaker for trees of equal frequency
237
+ */
238
+
239
+ #ifdef LIT_MEM
240
+ ushf *d_buf; /* buffer for distances */
241
+ uchf *l_buf; /* buffer for literals/lengths */
242
+ #else
243
+ uchf *sym_buf; /* buffer for distances and literals/lengths */
244
+ #endif
245
+
246
+ uInt lit_bufsize;
247
+ /* Size of match buffer for literals/lengths. There are 4 reasons for
248
+ * limiting lit_bufsize to 64K:
249
+ * - frequencies can be kept in 16 bit counters
250
+ * - if compression is not successful for the first block, all input
251
+ * data is still in the window so we can still emit a stored block even
252
+ * when input comes from standard input. (This can also be done for
253
+ * all blocks if lit_bufsize is not greater than 32K.)
254
+ * - if compression is not successful for a file smaller than 64K, we can
255
+ * even emit a stored file instead of a stored block (saving 5 bytes).
256
+ * This is applicable only for zip (not gzip or zlib).
257
+ * - creating new Huffman trees less frequently may not provide fast
258
+ * adaptation to changes in the input data statistics. (Take for
259
+ * example a binary file with poorly compressible code followed by
260
+ * a highly compressible string table.) Smaller buffer sizes give
261
+ * fast adaptation but have of course the overhead of transmitting
262
+ * trees more frequently.
263
+ * - I can't count above 4
264
+ */
265
+
266
+ uInt sym_next; /* running index in symbol buffer */
267
+ uInt sym_end; /* symbol table full when sym_next reaches this */
268
+
269
+ ulg opt_len; /* bit length of current block with optimal trees */
270
+ ulg static_len; /* bit length of current block with static trees */
271
+ uInt matches; /* number of string matches in current block */
272
+ uInt insert; /* bytes at end of window left to insert */
273
+
274
+ #ifdef ZLIB_DEBUG
275
+ ulg compressed_len; /* total bit length of compressed file mod 2^32 */
276
+ ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
277
+ #endif
278
+
279
+ #if defined(DEFLATE_CHUNK_WRITE_64LE)
280
+ uint64_t bi_buf;
281
+ #else
282
+ ush bi_buf;
283
+ #endif
284
+ /* Output buffer. bits are inserted starting at the bottom (least
285
+ * significant bits).
286
+ */
287
+ int bi_valid;
288
+ /* Number of valid bits in bi_buf. All bits above the last valid bit
289
+ * are always zero.
290
+ */
291
+ int bi_used;
292
+ /* Last number of used bits when going to a byte boundary.
293
+ */
294
+
295
+ ulg high_water;
296
+ /* High water mark offset in window for initialized bytes -- bytes above
297
+ * this are set to zero in order to avoid memory check warnings when
298
+ * longest match routines access bytes past the input. This is then
299
+ * updated to the new high water mark.
300
+ */
301
+
302
+ uInt chromium_zlib_hash;
303
+ /* 0 if Rabin-Karp rolling hash is enabled, non-zero if chromium zlib
304
+ * hash is enabled.
305
+ */
306
+
307
+ #if defined(QAT_COMPRESSION_ENABLED)
308
+ /* Pointer to a struct that contains the current state of the QAT
309
+ * stream.
310
+ */
311
+ struct qat_deflate *qat_s;
312
+ #endif
313
+
314
+ int slid;
315
+ /* True if the hash table has been slid since it was cleared. */
316
+
317
+ } FAR deflate_state;
318
+
319
+ /* Output a byte on the stream.
320
+ * IN assertion: there is enough room in pending_buf.
321
+ */
322
+ #define put_byte(s, c) {s->pending_buf[s->pending++] = (Bytef)(c);}
323
+
324
+
325
+ #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
326
+ /* Minimum amount of lookahead, except at the end of the input file.
327
+ * See deflate.c for comments about the MIN_MATCH+1.
328
+ */
329
+
330
+ #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
331
+ /* In order to simplify the code, particularly on 16 bit machines, match
332
+ * distances are limited to MAX_DIST instead of WSIZE.
333
+ */
334
+
335
+ #define WIN_INIT MAX_MATCH
336
+ /* Number of bytes after end of data in window to initialize in order to avoid
337
+ memory checker errors from longest match routines */
338
+
339
+ /* in trees.c */
340
+ void ZLIB_INTERNAL _tr_init(deflate_state *s);
341
+ int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc);
342
+ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
343
+ ulg stored_len, int last);
344
+ void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
345
+ void ZLIB_INTERNAL _tr_align(deflate_state *s);
346
+ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
347
+ ulg stored_len, int last);
348
+
349
+ #define d_code(dist) \
350
+ ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
351
+ /* Mapping from a distance to a distance code. dist is the distance - 1 and
352
+ * must not have side effects. _dist_code[256] and _dist_code[257] are never
353
+ * used.
354
+ */
355
+
356
+ #ifndef ZLIB_DEBUG
357
+ /* Inline versions of _tr_tally for speed: */
358
+
359
+ #if defined(GEN_TREES_H) || !defined(STDC)
360
+ extern uch ZLIB_INTERNAL _length_code[];
361
+ extern uch ZLIB_INTERNAL _dist_code[];
362
+ #else
363
+ extern const uch ZLIB_INTERNAL _length_code[];
364
+ extern const uch ZLIB_INTERNAL _dist_code[];
365
+ #endif
366
+
367
+ #ifdef LIT_MEM
368
+ # define _tr_tally_lit(s, c, flush) \
369
+ { uch cc = (c); \
370
+ s->d_buf[s->sym_next] = 0; \
371
+ s->l_buf[s->sym_next++] = cc; \
372
+ s->dyn_ltree[cc].Freq++; \
373
+ flush = (s->sym_next == s->sym_end); \
374
+ }
375
+ # define _tr_tally_dist(s, distance, length, flush) \
376
+ { uch len = (uch)(length); \
377
+ ush dist = (ush)(distance); \
378
+ s->d_buf[s->sym_next] = dist; \
379
+ s->l_buf[s->sym_next++] = len; \
380
+ dist--; \
381
+ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
382
+ s->dyn_dtree[d_code(dist)].Freq++; \
383
+ flush = (s->sym_next == s->sym_end); \
384
+ }
385
+ #else
386
+ # define _tr_tally_lit(s, c, flush) \
387
+ { uch cc = (c); \
388
+ s->sym_buf[s->sym_next++] = 0; \
389
+ s->sym_buf[s->sym_next++] = 0; \
390
+ s->sym_buf[s->sym_next++] = cc; \
391
+ s->dyn_ltree[cc].Freq++; \
392
+ flush = (s->sym_next == s->sym_end); \
393
+ }
394
+ # define _tr_tally_dist(s, distance, length, flush) \
395
+ { uch len = (uch)(length); \
396
+ ush dist = (ush)(distance); \
397
+ s->sym_buf[s->sym_next++] = (uch)dist; \
398
+ s->sym_buf[s->sym_next++] = (uch)(dist >> 8); \
399
+ s->sym_buf[s->sym_next++] = len; \
400
+ dist--; \
401
+ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
402
+ s->dyn_dtree[d_code(dist)].Freq++; \
403
+ flush = (s->sym_next == s->sym_end); \
404
+ }
405
+ #endif
406
+ #else
407
+ # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
408
+ # define _tr_tally_dist(s, distance, length, flush) \
409
+ flush = _tr_tally(s, distance, length)
410
+ #endif
411
+
412
+ /* Functions that are SIMD optimised on x86 */
413
+ void ZLIB_INTERNAL crc_fold_init(deflate_state* const s);
414
+ void ZLIB_INTERNAL crc_fold_copy(deflate_state* const s,
415
+ unsigned char* dst,
416
+ const unsigned char* src,
417
+ long len);
418
+ unsigned ZLIB_INTERNAL crc_fold_512to32(deflate_state* const s);
419
+
420
+ #endif /* DEFLATE_H */
@@ -0,0 +1,22 @@
1
+ /* deflate_crc32.c -- gzip CRC-32 helpers for the Chromium deflate.c
2
+ *
3
+ * Chromium's crc32.c owns crc_reset(), crc_finalize() and copy_with_crc(),
4
+ * which deflate.c calls unconditionally on the gzip path. This build keeps
5
+ * madler's crc32.c, so the three functions are provided here without the
6
+ * SIMD folding they carry upstream.
7
+ */
8
+
9
+ #include "deflate.h"
10
+
11
+ void ZLIB_INTERNAL crc_reset(deflate_state *const s) {
12
+ s->strm->adler = crc32(0L, Z_NULL, 0);
13
+ }
14
+
15
+ void ZLIB_INTERNAL crc_finalize(deflate_state *const s) {
16
+ (void)s;
17
+ }
18
+
19
+ void ZLIB_INTERNAL copy_with_crc(z_streamp strm, Bytef *dst, long size) {
20
+ zmemcpy(dst, strm->next_in, size);
21
+ strm->adler = crc32(strm->adler, dst, size);
22
+ }
package/src/inffast.h ADDED
@@ -0,0 +1,26 @@
1
+ /* inffast.h -- header to use inffast.c
2
+ * Copyright (C) 1995-2003, 2010 Mark Adler
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
+ /* INFLATE_FAST_MIN_INPUT: the minimum number of input bytes needed so that
12
+ we can safely call inflate_fast() with only one up-front bounds check. One
13
+ length/distance code pair (15 bits for the length code, 5 bits for length
14
+ extra, 15 bits for the distance code, 13 bits for distance extra) requires
15
+ reading up to 48 input bits (6 bytes).
16
+ */
17
+ #define INFLATE_FAST_MIN_INPUT 6
18
+
19
+ /* INFLATE_FAST_MIN_OUTPUT: the minimum number of output bytes needed so that
20
+ we can safely call inflate_fast() with only one up-front bounds check. One
21
+ length/distance code pair can output up to 258 bytes, which is the maximum
22
+ length that can be coded.
23
+ */
24
+ #define INFLATE_FAST_MIN_OUTPUT 258
25
+
26
+ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start);