Fossil SCM

addremove two files not handled by the previous patch file.

stephan 2014-08-19 18:49 miniz
Commit ca5d6f2b482bd08c58886b0fd4a96aaffc56f893
2 files changed +1698
+1698
--- a/src/miniz.h
+++ b/src/miniz.h
@@ -0,0 +1,1698 @@
1
+#ifndef MINIZ_HEADER_INCLUDED
2
+#define MINIZ_HEADER_INCLUDED
3
+
4
+#include <stdlib.h>
5
+
6
+// Defines to completely disable specific portions of miniz.c:
7
+// If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
8
+
9
+// Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O.
10
+#define MINIZ_NO_STDIO
11
+
12
+// If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or
13
+// get/set file times, and the C run-time funcs that get/set times won't be called.
14
+// The current downside is the times written to your archives will be from 1979.
15
+#define MINIZ_NO_TIME
16
+
17
+// Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's.
18
+#define MINIZ_NO_ARCHIVE_APIS
19
+
20
+// Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's.
21
+#define MINIZ_NO_ARCHIVE_WRITING_APIS
22
+
23
+// Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's.
24
+//#define MINIZ_NO_ZLIB_APIS
25
+
26
+// Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib.
27
+//#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
28
+
29
+// Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
30
+// Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
31
+// callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
32
+// functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work.
33
+//#define MINIZ_NO_MALLOC
34
+
35
+#if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
36
+ // TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux
37
+ #define MINIZ_NO_TIME
38
+#endif
39
+
40
+#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
41
+ #include <time.h>
42
+#endif
43
+
44
+#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
45
+// MINIZ_X86_OR_X64_CPU is only used to help set the below macros.
46
+#define MINIZ_X86_OR_X64_CPU 1
47
+#endif
48
+
49
+#if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
50
+// Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian.
51
+#define MINIZ_LITTLE_ENDIAN 1
52
+#endif
53
+
54
+#if MINIZ_X86_OR_X64_CPU
55
+// Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses.
56
+#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
57
+#endif
58
+
59
+#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
60
+// Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions).
61
+#define MINIZ_HAS_64BIT_REGISTERS 1
62
+#endif
63
+
64
+#ifdef __cplusplus
65
+extern "C" {
66
+#endif
67
+
68
+// ------------------- zlib-style API Definitions.
69
+
70
+// For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits!
71
+typedef unsigned long mz_ulong;
72
+
73
+// mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap.
74
+void mz_free(void *p);
75
+
76
+#define MZ_ADLER32_INIT (1)
77
+// mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
78
+mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
79
+
80
+#define MZ_CRC32_INIT (0)
81
+// mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL.
82
+mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
83
+
84
+// Compression strategies.
85
+enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 };
86
+
87
+// Method
88
+#define MZ_DEFLATED 8
89
+
90
+#ifndef MINIZ_NO_ZLIB_APIS
91
+
92
+// Heap allocation callbacks.
93
+// Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long.
94
+typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
95
+typedef void (*mz_free_func)(void *opaque, void *address);
96
+typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
97
+
98
+#define MZ_VERSION "9.1.15"
99
+#define MZ_VERNUM 0x91F0
100
+#define MZ_VER_MAJOR 9
101
+#define MZ_VER_MINOR 1
102
+#define MZ_VER_REVISION 15
103
+#define MZ_VER_SUBREVISION 0
104
+
105
+// Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs).
106
+enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
107
+
108
+// Return status codes. MZ_PARAM_ERROR is non-standard.
109
+enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 };
110
+
111
+// Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL.
112
+enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 };
113
+
114
+// Window bits
115
+#define MZ_DEFAULT_WINDOW_BITS 15
116
+
117
+struct mz_internal_state;
118
+
119
+// Compression/decompression stream struct.
120
+typedef struct mz_stream_s
121
+{
122
+ const unsigned char *next_in; // pointer to next byte to read
123
+ unsigned int avail_in; // number of bytes available at next_in
124
+ mz_ulong total_in; // total number of bytes consumed so far
125
+
126
+ unsigned char *next_out; // pointer to next byte to write
127
+ unsigned int avail_out; // number of bytes that can be written to next_out
128
+ mz_ulong total_out; // total number of bytes produced so far
129
+
130
+ char *msg; // error msg (unused)
131
+ struct mz_internal_state *state; // internal state, allocated by zalloc/zfree
132
+
133
+ mz_alloc_func zalloc; // optional heap allocation function (defaults to malloc)
134
+ mz_free_func zfree; // optional heap free function (defaults to free)
135
+ void *opaque; // heap alloc function user pointer
136
+
137
+ int data_type; // data_type (unused)
138
+ mz_ulong adler; // adler32 of the source or uncompressed data
139
+ mz_ulong reserved; // not used
140
+} mz_stream;
141
+
142
+typedef mz_stream *mz_streamp;
143
+
144
+// Returns the version string of miniz.c.
145
+const char *mz_version(void);
146
+
147
+// mz_deflateInit() initializes a compressor with default options:
148
+// Parameters:
149
+// pStream must point to an initialized mz_stream struct.
150
+// level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION].
151
+// level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
152
+// (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.)
153
+// Return values:
154
+// MZ_OK on success.
155
+// MZ_STREAM_ERROR if the stream is bogus.
156
+// MZ_PARAM_ERROR if the input parameters are bogus.
157
+// MZ_MEM_ERROR on out of memory.
158
+int mz_deflateInit(mz_streamp pStream, int level);
159
+
160
+// mz_deflateInit2() is like mz_deflate(), except with more control:
161
+// Additional parameters:
162
+// method must be MZ_DEFLATED
163
+// window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer)
164
+// mem_level must be between [1, 9] (it's checked but ignored by miniz.c)
165
+int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
166
+
167
+// Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2().
168
+int mz_deflateReset(mz_streamp pStream);
169
+
170
+// mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
171
+// Parameters:
172
+// pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
173
+// flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH.
174
+// Return values:
175
+// MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full).
176
+// MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore.
177
+// MZ_STREAM_ERROR if the stream is bogus.
178
+// MZ_PARAM_ERROR if one of the parameters is invalid.
179
+// MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.)
180
+int mz_deflate(mz_streamp pStream, int flush);
181
+
182
+// mz_deflateEnd() deinitializes a compressor:
183
+// Return values:
184
+// MZ_OK on success.
185
+// MZ_STREAM_ERROR if the stream is bogus.
186
+int mz_deflateEnd(mz_streamp pStream);
187
+
188
+// mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH.
189
+mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
190
+
191
+// Single-call compression functions mz_compress() and mz_compress2():
192
+// Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure.
193
+int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
194
+int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level);
195
+
196
+// mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress().
197
+mz_ulong mz_compressBound(mz_ulong source_len);
198
+
199
+// Initializes a decompressor.
200
+int mz_inflateInit(mz_streamp pStream);
201
+
202
+// mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer:
203
+// window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate).
204
+int mz_inflateInit2(mz_streamp pStream, int window_bits);
205
+
206
+// Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible.
207
+// Parameters:
208
+// pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
209
+// flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH.
210
+// On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster).
211
+// MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data.
212
+// Return values:
213
+// MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full.
214
+// MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified.
215
+// MZ_STREAM_ERROR if the stream is bogus.
216
+// MZ_DATA_ERROR if the deflate stream is invalid.
217
+// MZ_PARAM_ERROR if one of the parameters is invalid.
218
+// MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again
219
+// with more input data, or with more room in the output buffer (except when using single call decompression, described above).
220
+int mz_inflate(mz_streamp pStream, int flush);
221
+
222
+// Deinitializes a decompressor.
223
+int mz_inflateEnd(mz_streamp pStream);
224
+
225
+// Single-call decompression.
226
+// Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure.
227
+int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
228
+
229
+// Returns a string description of the specified error code, or NULL if the error code is invalid.
230
+const char *mz_error(int err);
231
+
232
+// Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset of zlib that miniz.c supports.
233
+// Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project.
234
+#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
235
+ typedef unsigned char Byte;
236
+ typedef unsigned int uInt;
237
+ typedef mz_ulong uLong;
238
+ typedef Byte Bytef;
239
+ typedef uInt uIntf;
240
+ typedef char charf;
241
+ typedef int intf;
242
+ typedef void *voidpf;
243
+ typedef uLong uLongf;
244
+ typedef void *voidp;
245
+ typedef void *const voidpc;
246
+ #define Z_NULL 0
247
+ #define Z_NO_FLUSH MZ_NO_FLUSH
248
+ #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
249
+ #define Z_SYNC_FLUSH MZ_SYNC_FLUSH
250
+ #define Z_FULL_FLUSH MZ_FULL_FLUSH
251
+ #define Z_FINISH MZ_FINISH
252
+ #define Z_BLOCK MZ_BLOCK
253
+ #define Z_OK MZ_OK
254
+ #define Z_STREAM_END MZ_STREAM_END
255
+ #define Z_NEED_DICT MZ_NEED_DICT
256
+ #define Z_ERRNO MZ_ERRNO
257
+ #define Z_STREAM_ERROR MZ_STREAM_ERROR
258
+ #define Z_DATA_ERROR MZ_DATA_ERROR
259
+ #define Z_MEM_ERROR MZ_MEM_ERROR
260
+ #define Z_BUF_ERROR MZ_BUF_ERROR
261
+ #define Z_VERSION_ERROR MZ_VERSION_ERROR
262
+ #define Z_PARAM_ERROR MZ_PARAM_ERROR
263
+ #define Z_NO_COMPRESSION MZ_NO_COMPRESSION
264
+ #define Z_BEST_SPEED MZ_BEST_SPEED
265
+ #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION
266
+ #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
267
+ #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY
268
+ #define Z_FILTERED MZ_FILTERED
269
+ #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY
270
+ #define Z_RLE MZ_RLE
271
+ #define Z_FIXED MZ_FIXED
272
+ #define Z_DEFLATED MZ_DEFLATED
273
+ #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
274
+ #define alloc_func mz_alloc_func
275
+ #define free_func mz_free_func
276
+ #define internal_state mz_internal_state
277
+ #define z_stream mz_stream
278
+ #define deflateInit mz_deflateInit
279
+ #define deflateInit2 mz_deflateInit2
280
+ #define deflateReset mz_deflateReset
281
+ #define deflate mz_deflate
282
+ #define deflateEnd mz_deflateEnd
283
+ #define deflateBound mz_deflateBound
284
+ #define compress mz_compress
285
+ #define compress2 mz_compress2
286
+ #define compressBound mz_compressBound
287
+ #define inflateInit mz_inflateInit
288
+ #define inflateInit2 mz_inflateInit2
289
+ #define inflate mz_inflate
290
+ #define inflateEnd mz_inflateEnd
291
+ #define uncompress mz_uncompress
292
+ #define crc32 mz_crc32
293
+ #define adler32 mz_adler32
294
+ #define MAX_WBITS 15
295
+ #define MAX_MEM_LEVEL 9
296
+ #define zError mz_error
297
+ #define ZLIB_VERSION MZ_VERSION
298
+ #define ZLIB_VERNUM MZ_VERNUM
299
+ #define ZLIB_VER_MAJOR MZ_VER_MAJOR
300
+ #define ZLIB_VER_MINOR MZ_VER_MINOR
301
+ #define ZLIB_VER_REVISION MZ_VER_REVISION
302
+ #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
303
+ #define zlibVersion mz_version
304
+ #define zlib_version mz_version()
305
+#endif // #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
306
+
307
+#endif // MINIZ_NO_ZLIB_APIS
308
+
309
+// ------------------- Types and macros
310
+
311
+typedef unsigned char mz_uint8;
312
+typedef signed short mz_int16;
313
+typedef unsigned short mz_uint16;
314
+typedef unsigned int mz_uint32;
315
+typedef unsigned int mz_uint;
316
+typedef long long mz_int64;
317
+typedef unsigned long long mz_uint64;
318
+typedef int mz_bool;
319
+
320
+#define MZ_FALSE (0)
321
+#define MZ_TRUE (1)
322
+
323
+// An attempt to work around MSVC's spammy "warning C4127: conditional expression is constant" message.
324
+#ifdef _MSC_VER
325
+ #define MZ_MACRO_END while (0, 0)
326
+#else
327
+ #define MZ_MACRO_END while (0)
328
+#endif
329
+
330
+// ------------------- ZIP archive reading/writing
331
+
332
+#ifndef MINIZ_NO_ARCHIVE_APIS
333
+
334
+enum
335
+{
336
+ MZ_ZIP_MAX_IO_BUF_SIZE = 64*1024,
337
+ MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 260,
338
+ MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 256
339
+};
340
+
341
+typedef struct
342
+{
343
+ mz_uint32 m_file_index;
344
+ mz_uint32 m_central_dir_ofs;
345
+ mz_uint16 m_version_made_by;
346
+ mz_uint16 m_version_needed;
347
+ mz_uint16 m_bit_flag;
348
+ mz_uint16 m_method;
349
+#ifndef MINIZ_NO_TIME
350
+ time_t m_time;
351
+#endif
352
+ mz_uint32 m_crc32;
353
+ mz_uint64 m_comp_size;
354
+ mz_uint64 m_uncomp_size;
355
+ mz_uint16 m_internal_attr;
356
+ mz_uint32 m_external_attr;
357
+ mz_uint64 m_local_header_ofs;
358
+ mz_uint32 m_comment_size;
359
+ char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
360
+ char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
361
+} mz_zip_archive_file_stat;
362
+
363
+typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
364
+typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
365
+
366
+struct mz_zip_internal_state_tag;
367
+typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
368
+
369
+typedef enum
370
+{
371
+ MZ_ZIP_MODE_INVALID = 0,
372
+ MZ_ZIP_MODE_READING = 1,
373
+ MZ_ZIP_MODE_WRITING = 2,
374
+ MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
375
+} mz_zip_mode;
376
+
377
+typedef struct mz_zip_archive_tag
378
+{
379
+ mz_uint64 m_archive_size;
380
+ mz_uint64 m_central_directory_file_ofs;
381
+ mz_uint m_total_files;
382
+ mz_zip_mode m_zip_mode;
383
+
384
+ mz_uint m_file_offset_alignment;
385
+
386
+ mz_alloc_func m_pAlloc;
387
+ mz_free_func m_pFree;
388
+ mz_realloc_func m_pRealloc;
389
+ void *m_pAlloc_opaque;
390
+
391
+ mz_file_read_func m_pRead;
392
+ mz_file_write_func m_pWrite;
393
+ void *m_pIO_opaque;
394
+
395
+ mz_zip_internal_state *m_pState;
396
+
397
+} mz_zip_archive;
398
+
399
+typedef enum
400
+{
401
+ MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
402
+ MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
403
+ MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
404
+ MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800
405
+} mz_zip_flags;
406
+
407
+// ZIP archive reading
408
+
409
+// Inits a ZIP archive reader.
410
+// These functions read and validate the archive's central directory.
411
+mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint32 flags);
412
+mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint32 flags);
413
+
414
+#ifndef MINIZ_NO_STDIO
415
+mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
416
+#endif
417
+
418
+// Returns the total number of files in the archive.
419
+mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
420
+
421
+// Returns detailed information about an archive file entry.
422
+mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
423
+
424
+// Determines if an archive file entry is a directory entry.
425
+mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
426
+mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
427
+
428
+// Retrieves the filename of an archive file entry.
429
+// Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename.
430
+mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
431
+
432
+// Attempts to locates a file in the archive's central directory.
433
+// Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH
434
+// Returns -1 if the file cannot be found.
435
+int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
436
+
437
+// Extracts a archive file to a memory buffer using no memory allocation.
438
+mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
439
+mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
440
+
441
+// Extracts a archive file to a memory buffer.
442
+mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags);
443
+mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags);
444
+
445
+// Extracts a archive file to a dynamically allocated heap buffer.
446
+void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
447
+void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
448
+
449
+// Extracts a archive file using a callback function to output the file's data.
450
+mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
451
+mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
452
+
453
+#ifndef MINIZ_NO_STDIO
454
+// Extracts a archive file to a disk file and sets its last accessed and modified times.
455
+// This function only extracts files, not archive directory records.
456
+mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
457
+mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
458
+#endif
459
+
460
+// Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used.
461
+mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
462
+
463
+// ZIP archive writing
464
+
465
+#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
466
+
467
+// Inits a ZIP archive writer.
468
+mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
469
+mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
470
+
471
+#ifndef MINIZ_NO_STDIO
472
+mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
473
+#endif
474
+
475
+// Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive.
476
+// For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for writing. If the file can't be reopened, mz_zip_reader_end() will be called.
477
+// For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which defaults to realloc unless you've overridden it).
478
+// Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL.
479
+// Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before
480
+// the archive is finalized the file's central directory will be hosed.
481
+mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
482
+
483
+// Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive.
484
+// To add a directory entry, call this method with an archive name ending in a forwardslash with empty buffer.
485
+// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
486
+mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags);
487
+mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
488
+
489
+#ifndef MINIZ_NO_STDIO
490
+// Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive.
491
+// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
492
+mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
493
+#endif
494
+
495
+// Adds a file to an archive by fully cloning the data from another archive.
496
+// This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data, and comment fields.
497
+mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint file_index);
498
+
499
+// Finalizes the archive by writing the central directory records followed by the end of central directory record.
500
+// After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end().
501
+// An archive must be manually finalized by calling this function for it to be valid.
502
+mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
503
+mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **pBuf, size_t *pSize);
504
+
505
+// Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used.
506
+// Note for the archive to be valid, it must have been finalized before ending.
507
+mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
508
+
509
+// Misc. high-level helper functions:
510
+
511
+// mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive.
512
+// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
513
+mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
514
+
515
+// Reads a single file from an archive into a heap block.
516
+// Returns NULL on failure.
517
+void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint zip_flags);
518
+
519
+#endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
520
+
521
+#endif // #ifndef MINIZ_NO_ARCHIVE_APIS
522
+
523
+// ------------------- Low-level Decompression API Definitions
524
+
525
+// Decompression flags used by tinfl_decompress().
526
+// TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream.
527
+// TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input.
528
+// TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB).
529
+// TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes.
530
+enum
531
+{
532
+ TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
533
+ TINFL_FLAG_HAS_MORE_INPUT = 2,
534
+ TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
535
+ TINFL_FLAG_COMPUTE_ADLER32 = 8
536
+};
537
+
538
+// High level decompression functions:
539
+// tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc().
540
+// On entry:
541
+// pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress.
542
+// On return:
543
+// Function returns a pointer to the decompressed data, or NULL on failure.
544
+// *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data.
545
+// The caller must call mz_free() on the returned block when it's no longer needed.
546
+void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
547
+
548
+// tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory.
549
+// Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success.
550
+#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
551
+size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
552
+
553
+// tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer.
554
+// Returns 1 on success or 0 on failure.
555
+typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
556
+int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
557
+
558
+struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor;
559
+
560
+// Max size of LZ dictionary.
561
+#define TINFL_LZ_DICT_SIZE 32768
562
+
563
+// Return status.
564
+typedef enum
565
+{
566
+ TINFL_STATUS_BAD_PARAM = -3,
567
+ TINFL_STATUS_ADLER32_MISMATCH = -2,
568
+ TINFL_STATUS_FAILED = -1,
569
+ TINFL_STATUS_DONE = 0,
570
+ TINFL_STATUS_NEEDS_MORE_INPUT = 1,
571
+ TINFL_STATUS_HAS_MORE_OUTPUT = 2
572
+} tinfl_status;
573
+
574
+// Initializes the decompressor to its initial state.
575
+#define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END
576
+#define tinfl_get_adler32(r) (r)->m_check_adler32
577
+
578
+// Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability.
579
+// This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output.
580
+tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags);
581
+
582
+// Internal/private bits follow.
583
+enum
584
+{
585
+ TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19,
586
+ TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
587
+};
588
+
589
+typedef struct
590
+{
591
+ mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
592
+ mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
593
+} tinfl_huff_table;
594
+
595
+#if MINIZ_HAS_64BIT_REGISTERS
596
+ #define TINFL_USE_64BIT_BITBUF 1
597
+#endif
598
+
599
+#if TINFL_USE_64BIT_BITBUF
600
+ typedef mz_uint64 tinfl_bit_buf_t;
601
+ #define TINFL_BITBUF_SIZE (64)
602
+#else
603
+ typedef mz_uint32 tinfl_bit_buf_t;
604
+ #define TINFL_BITBUF_SIZE (32)
605
+#endif
606
+
607
+struct tinfl_decompressor_tag
608
+{
609
+ mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES];
610
+ tinfl_bit_buf_t m_bit_buf;
611
+ size_t m_dist_from_out_buf_start;
612
+ tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
613
+ mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
614
+};
615
+
616
+// ------------------- Low-level Compression API Definitions
617
+
618
+// Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently).
619
+#define TDEFL_LESS_MEMORY 0
620
+
621
+// tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search):
622
+// TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression).
623
+enum
624
+{
625
+ TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF
626
+};
627
+
628
+// TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data.
629
+// TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers).
630
+// TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing.
631
+// TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory).
632
+// TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1)
633
+// TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled.
634
+// TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables.
635
+// TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks.
636
+// The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK).
637
+enum
638
+{
639
+ TDEFL_WRITE_ZLIB_HEADER = 0x01000,
640
+ TDEFL_COMPUTE_ADLER32 = 0x02000,
641
+ TDEFL_GREEDY_PARSING_FLAG = 0x04000,
642
+ TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
643
+ TDEFL_RLE_MATCHES = 0x10000,
644
+ TDEFL_FILTER_MATCHES = 0x20000,
645
+ TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000,
646
+ TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
647
+};
648
+
649
+// High level compression functions:
650
+// tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc().
651
+// On entry:
652
+// pSrc_buf, src_buf_len: Pointer and size of source block to compress.
653
+// flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression.
654
+// On return:
655
+// Function returns a pointer to the compressed data, or NULL on failure.
656
+// *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data.
657
+// The caller must free() the returned block when it's no longer needed.
658
+void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
659
+
660
+// tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory.
661
+// Returns 0 on failure.
662
+size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
663
+
664
+// Compresses an image to a compressed PNG file in memory.
665
+// On entry:
666
+// pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4.
667
+// The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory.
668
+// level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc. or a decent default is MZ_DEFAULT_LEVEL
669
+// If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps).
670
+// On return:
671
+// Function returns a pointer to the compressed data, or NULL on failure.
672
+// *pLen_out will be set to the size of the PNG image file.
673
+// The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
674
+void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip);
675
+void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
676
+
677
+// Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
678
+typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
679
+
680
+// tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally.
681
+mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
682
+
683
+enum { TDEFL_MAX_HUFF_TABLES = 3, TDEFL_MAX_HUFF_SYMBOLS_0 = 288, TDEFL_MAX_HUFF_SYMBOLS_1 = 32, TDEFL_MAX_HUFF_SYMBOLS_2 = 19, TDEFL_LZ_DICT_SIZE = 32768, TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, TDEFL_MIN_MATCH_LEN = 3, TDEFL_MAX_MATCH_LEN = 258 };
684
+
685
+// TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes).
686
+#if TDEFL_LESS_MEMORY
687
+enum { TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 12, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
688
+#else
689
+enum { TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 15, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
690
+#endif
691
+
692
+// The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions.
693
+typedef enum
694
+{
695
+ TDEFL_STATUS_BAD_PARAM = -2,
696
+ TDEFL_STATUS_PUT_BUF_FAILED = -1,
697
+ TDEFL_STATUS_OKAY = 0,
698
+ TDEFL_STATUS_DONE = 1,
699
+} tdefl_status;
700
+
701
+// Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums
702
+typedef enum
703
+{
704
+ TDEFL_NO_FLUSH = 0,
705
+ TDEFL_SYNC_FLUSH = 2,
706
+ TDEFL_FULL_FLUSH = 3,
707
+ TDEFL_FINISH = 4
708
+} tdefl_flush;
709
+
710
+// tdefl's compression state structure.
711
+typedef struct
712
+{
713
+ tdefl_put_buf_func_ptr m_pPut_buf_func;
714
+ void *m_pPut_buf_user;
715
+ mz_uint m_flags, m_max_probes[2];
716
+ int m_greedy_parsing;
717
+ mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size;
718
+ mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end;
719
+ mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer;
720
+ mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index, m_wants_to_finish;
721
+ tdefl_status m_prev_return_status;
722
+ const void *m_pIn_buf;
723
+ void *m_pOut_buf;
724
+ size_t *m_pIn_buf_size, *m_pOut_buf_size;
725
+ tdefl_flush m_flush;
726
+ const mz_uint8 *m_pSrc;
727
+ size_t m_src_buf_left, m_out_buf_ofs;
728
+ mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1];
729
+ mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
730
+ mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
731
+ mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
732
+ mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE];
733
+ mz_uint16 m_next[TDEFL_LZ_DICT_SIZE];
734
+ mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE];
735
+ mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
736
+} tdefl_compressor;
737
+
738
+// Initializes the compressor.
739
+// There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory.
740
+// pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression.
741
+// If pBut_buf_func is NULL the user should always call the tdefl_compress() API.
742
+// flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.)
743
+tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
744
+
745
+// Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much compressed data to the specified output buffer as possible.
746
+tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush);
747
+
748
+// tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr.
749
+// tdefl_compress_buffer() always consumes the entire input buffer.
750
+tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush);
751
+
752
+tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
753
+mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
754
+
755
+// Can't use tdefl_create_comp_flags_from_zip_params if MINIZ_NO_ZLIB_APIS isn't defined, because it uses some of its macros.
756
+#ifndef MINIZ_NO_ZLIB_APIS
757
+// Create tdefl_compress() flags given zlib-style compression parameters.
758
+// level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files)
759
+// window_bits may be -15 (raw deflate) or 15 (zlib)
760
+// strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED
761
+mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
762
+#endif // #ifndef MINIZ_NO_ZLIB_APIS
763
+
764
+#ifdef __cplusplus
765
+}
766
+#endif
767
+
768
+#endif // MINIZ_HEADER_INCLUDED
769
+
770
+#ifndef MINIZ_HEADER_INCLUDED
771
+#define MINIZ_HEADER_INCLUDED
772
+
773
+#include <stdlib.h>
774
+
775
+// Defines to completely disable specific portions of miniz.c:
776
+// If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
777
+
778
+// Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O.
779
+#define MINIZ_NO_STDIO
780
+
781
+// If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or
782
+// get/set file times, and the C run-time funcs that get/set times won't be called.
783
+// The current downside is the times written to your archives will be from 1979.
784
+#define MINIZ_NO_TIME
785
+
786
+// Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's.
787
+#define MINIZ_NO_ARCHIVE_APIS
788
+
789
+// Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's.
790
+#define MINIZ_NO_ARCHIVE_WRITING_APIS
791
+
792
+// Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's.
793
+//#define MINIZ_NO_ZLIB_APIS
794
+
795
+// Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib.
796
+//#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
797
+
798
+// Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
799
+// Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
800
+// callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
801
+// functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work.
802
+//#define MINIZ_NO_MALLOC
803
+
804
+#if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
805
+ // TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux
806
+ #define MINIZ_NO_TIME
807
+#endif
808
+
809
+#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
810
+ #include <time.h>
811
+#endif
812
+
813
+#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
814
+// MINIZ_X86_OR_X64_CPU is only used to help set the below macros.
815
+#define MINIZ_X86_OR_X64_CPU 1
816
+#endif
817
+
818
+#if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
819
+// Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian.
820
+#define MINIZ_LITTLE_ENDIAN 1
821
+#endif
822
+
823
+#if MINIZ_X86_OR_X64_CPU
824
+// Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses.
825
+#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
826
+#endif
827
+
828
+#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
829
+// Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions).
830
+#define MINIZ_HAS_64BIT_REGISTERS 1
831
+#endif
832
+
833
+#ifdef __cplusplus
834
+extern "C" {
835
+#endif
836
+
837
+// ------------------- zlib-style API Definitions.
838
+
839
+// For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits!
840
+typedef unsigned long mz_ulong;
841
+
842
+// mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap.
843
+void mz_free(void *p);
844
+
845
+#define MZ_ADLER32_INIT (1)
846
+// mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
847
+mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
848
+
849
+#define MZ_CRC32_INIT (0)
850
+// mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL.
851
+mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
852
+
853
+// Compression strategies.
854
+enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 };
855
+
856
+// Method
857
+#define MZ_DEFLATED 8
858
+
859
+#ifndef MINIZ_NO_ZLIB_APIS
860
+
861
+// Heap allocation callbacks.
862
+// Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long.
863
+typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
864
+typedef void (*mz_free_func)(void *opaque, void *address);
865
+typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
866
+
867
+#define MZ_VERSION "9.1.15"
868
+#define MZ_VERNUM 0x91F0
869
+#define MZ_VER_MAJOR 9
870
+#define MZ_VER_MINOR 1
871
+#define MZ_VER_REVISION 15
872
+#define MZ_VER_SUBREVISION 0
873
+
874
+// Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs).
875
+enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
876
+
877
+// Return status codes. MZ_PARAM_ERROR is non-standard.
878
+enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 };
879
+
880
+// Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL.
881
+enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 };
882
+
883
+// Window bits
884
+#define MZ_DEFAULT_WINDOW_BITS 15
885
+
886
+struct mz_internal_state;
887
+
888
+// Compression/decompression stream struct.
889
+typedef struct mz_stream_s
890
+{
891
+ const unsigned char *next_in; // pointer to next byte to read
892
+ unsigned int avail_in; // number of bytes available at next_in
893
+ mz_ulong total_in; // total number of bytes consumed so far
894
+
895
+ unsigned char *next_out; // pointer to next byte to write
896
+ unsigned int avail_out; // number of bytes that can be written to next_out
897
+ mz_ulong total_out; // total number of bytes produced so far
898
+
899
+ char *msg; // error msg (unused)
900
+ struct mz_internal_state *state; // internal state, allocated by zalloc/zfree
901
+
902
+ mz_alloc_func zalloc; // optional heap allocation function (defaults to malloc)
903
+ mz_free_func zfree; // optional heap free function (defaults to free)
904
+ void *opaque; // heap alloc function user pointer
905
+
906
+ int data_type; // data_type (unused)
907
+ mz_ulong adler; // adler32 of the source or uncompressed data
908
+ mz_ulong reserved; // not used
909
+} mz_stream;
910
+
911
+typedef mz_stream *mz_streamp;
912
+
913
+// Returns the version string of miniz.c.
914
+const char *mz_version(void);
915
+
916
+// mz_deflateInit() initializes a compressor with default options:
917
+// Parameters:
918
+// pStream must point to an initialized mz_stream struct.
919
+// level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION].
920
+// level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
921
+// (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.)
922
+// Return values:
923
+// MZ_OK on success.
924
+// MZ_STREAM_ERROR if the stream is bogus.
925
+// MZ_PARAM_ERROR if the input parameters are bogus.
926
+// MZ_MEM_ERROR on out of memory.
927
+int mz_deflateInit(mz_streamp pStream, int level);
928
+
929
+// mz_deflateInit2() is like mz_deflate(), except with more control:
930
+// Additional parameters:
931
+// method must be MZ_DEFLATED
932
+// window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer)
933
+// mem_level must be between [1, 9] (it's checked but ignored by miniz.c)
934
+int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
935
+
936
+// Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2().
937
+int mz_deflateReset(mz_streamp pStream);
938
+
939
+// mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
940
+// Parameters:
941
+// pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
942
+// flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH.
943
+// Return values:
944
+// MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full).
945
+// MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore.
946
+// MZ_STREAM_ERROR if the stream is bogus.
947
+// MZ_PARAM_ERROR if one of the parameters is invalid.
948
+// MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.)
949
+int mz_deflate(mz_streamp pStream, int flush);
950
+
951
+// mz_deflateEnd() deinitializes a compressor:
952
+// Return values:
953
+// MZ_OK on success.
954
+// MZ_STREAM_ERROR if the stream is bogus.
955
+int mz_deflateEnd(mz_streamp pStream);
956
+
957
+// mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH.
958
+mz_u
959
+#ifndef MINIZ_HEADER_INCLUDED
960
+#define MINIZ_HEADER_INCLUDED
961
+
962
+#include <stdlib.h>
963
+
964
+// Defines to completely disable specific portions of miniz.c:
965
+// If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
966
+
967
+// Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O.
968
+#define MINIZ_NO_STDIO
969
+
970
+// If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or
971
+// get/set file times, and the C run-time funcs that get/set times won't be called.
972
+// The current downside is the times written to your archives will be from 1979.
973
+#define MINIZ_NO_TIME
974
+
975
+// Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's.
976
+#define MINIZ_NO_ARCHIVE_APIS
977
+
978
+// Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's.
979
+#define MINIZ_NO_ARCHIVE_WRITING_APIS
980
+
981
+// Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's.
982
+//#define MINIZ_NO_ZLIB_APIS
983
+
984
+// Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib.
985
+//#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
986
+
987
+// Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
988
+// Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
989
+// callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
990
+// functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work.
991
+//#define MINIZ_NO_MALLOC
992
+
993
+#if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
994
+ // TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux
995
+ #define MINIZ_NO_TIME
996
+#endif
997
+
998
+#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
999
+ #include <time.h>
1000
+#endif
1001
+
1002
+#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
1003
+// MINIZ_X86_OR_X64_CPU is only used to help set the below macros.
1004
+#define MINIZ_X86_OR_X64_CPU 1
1005
+#endif
1006
+
1007
+#if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
1008
+// Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian.
1009
+#define MINIZ_LITTLE_ENDIAN 1
1010
+#endif
1011
+
1012
+#if MINIZ_X86_OR_X64_CPU
1013
+// Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses.
1014
+#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
1015
+#endif
1016
+
1017
+#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
1018
+// Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions).
1019
+#define MINIZ_HAS_64BIT_REGISTERS 1
1020
+#endif
1021
+
1022
+#ifdef __cplusplus
1023
+extern "C" {
1024
+#endif
1025
+
1026
+// ------------------- zlib-style API Definitions.
1027
+
1028
+// For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits!
1029
+typedef unsigned long mz_ulong;
1030
+
1031
+// mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap.
1032
+void mz_free(void *p);
1033
+
1034
+#define MZ_ADLER32_INIT (1)
1035
+// mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
1036
+mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
1037
+
1038
+#define MZ_CRC32_INIT (0)
1039
+// mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL.
1040
+mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
1041
+
1042
+// Compression strategies.
1043
+enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 };
1044
+
1045
+// Method
1046
+#define MZ_DEFLATED 8
1047
+
1048
+#ifndef MINIZ_NO_ZLIB_APIS
1049
+
1050
+// Heap allocation callbacks.
1051
+// Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long.
1052
+typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
1053
+typedef void (*mz_free_func)(void *opaque, void *address);
1054
+typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
1055
+
1056
+#define MZ_VERSION "9.1.15"
1057
+#define MZ_VERNUM 0x91F0
1058
+#define MZ_VER_MAJOR 9
1059
+#define MZ_VER_MINOR 1
1060
+#define MZ_VER_REVISION 15
1061
+#define MZ_VER_SUBREVISION 0
1062
+
1063
+// Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs).
1064
+enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
1065
+
1066
+// Return status codes. MZ_PARAM_ERROR is non-standard.
1067
+enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 };
1068
+
1069
+// Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL.
1070
+enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 };
1071
+
1072
+// Window bits
1073
+#define MZ_DEFAULT_WINDOW_BITS 15
1074
+
1075
+struct mz_internal_state;
1076
+
1077
+// Compression/decompression stream struct.
1078
+typedef struct mz_stream_s
1079
+{
1080
+ const unsigned char *next_in; // pointer to next byte to read
1081
+ unsigned int avail_in; // number of bytes available at next_in
1082
+ mz_ulong total_in; // total number of bytes consumed so far
1083
+
1084
+ unsigned char *next_out; // pointer to next byte to write
1085
+ unsigned int avail_out; // number of bytes that can be written to next_out
1086
+ mz_ulong total_out; // total number of bytes produced so far
1087
+
1088
+ char *msg; // error msg (unused)
1089
+ struct mz_internal_state *state; // internal state, allocated by zalloc/zfree
1090
+
1091
+ mz_alloc_func zalloc; // optional heap allocation function (defaults to malloc)
1092
+ mz_free_func zfree; // optional heap free function (defaults to free)
1093
+ void *opaque; // heap alloc function user pointer
1094
+
1095
+ int data_type; // data_type (unused)
1096
+ mz_ulong adler; // adler32 of the source or uncompressed data
1097
+ mz_ulong reserved; // not used
1098
+} mz_stream;
1099
+
1100
+typedef mz_stream *mz_streamp;
1101
+
1102
+// Returns the version string of miniz.c.
1103
+const char *mz_version(void);
1104
+
1105
+// mz_deflateInit() initializes a compressor with default options:
1106
+// Parameters:
1107
+// pStream must point to an initialized mz_stream struct.
1108
+// level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION].
1109
+// level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
1110
+// (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.)
1111
+// Return values:
1112
+// MZ_OK on success.
1113
+// MZ_STREAM_ERROR if the stream is bogus.
1114
+// MZ_PARAM_ERROR if the input parameters are bogus.
1115
+// MZ_MEM_ERROR on out of memory.
1116
+int mz_deflateInit(mz_streamp pStream, int level);
1117
+
1118
+// mz_deflateInit2() is like mz_deflate(), except with more control:
1119
+// Additional parameters:
1120
+// method must be MZ_DEFLATED
1121
+// window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer)
1122
+// mem_level must be between [1, 9] (it's checked but ignored by miniz.c)
1123
+int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
1124
+
1125
+// Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2().
1126
+int mz_deflateReset(mz_streamp pStream);
1127
+
1128
+// mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
1129
+// Parameters:
1130
+// pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
1131
+// flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH.
1132
+// Return values:
1133
+// MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full).
1134
+// MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore.
1135
+// MZ_STREAM_ERROR if the stream is bogus.
1136
+// MZ_PARAM_ERROR if one of the parameters is invalid.
1137
+// MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.)
1138
+int mz_deflate(mz_streamp pStream, int flush);
1139
+
1140
+// mz_deflateEnd() deinitializes a compressor:
1141
+// Return values:
1142
+// MZ_OK on success.
1143
+// MZ_STREAM_ERROR if the stream is bogus.
1144
+int mz_deflateEnd(mz_streamp pStream);
1145
+
1146
+// mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH.
1147
+mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
1148
+
1149
+// Single-call compression functions mz_compress() and mz_compress2():
1150
+// Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure.
1151
+int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
1152
+int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level);
1153
+
1154
+// mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress().
1155
+mz_ulong mz_compressBound(mz_ulong source_len);
1156
+
1157
+// Initializes a decompressor.
1158
+int mz_inflateInit(mz_streamp pStream);
1159
+
1160
+// mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer:
1161
+// window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate).
1162
+int mz_inflateInit2(mz_streamp pStream, int window_bits);
1163
+
1164
+// Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible.
1165
+// Parameters:
1166
+// pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
1167
+// flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH.
1168
+// On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster).
1169
+// MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data.
1170
+// Return values:
1171
+// MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full.
1172
+// MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified.
1173
+// MZ_STREAM_ERROR if the stream is bogus.
1174
+// MZ_DATA_ERROR if the deflate stream is invalid.
1175
+// MZ_PARAM_ERROR if one of the parameters is invalid.
1176
+// MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again
1177
+// with more input data, or with more room in the output buffer (except when using single call decompression, described above).
1178
+int mz_inflate(mz_streamp pStream, int flush);
1179
+
1180
+// Deinitializes a decompressor.
1181
+int mz_inflateEnd(mz_streamp pStream);
1182
+
1183
+// Single-call decompression.
1184
+// Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure.
1185
+int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
1186
+
1187
+// Returns a string description of the specified error code, or NULL if the error code is invalid.
1188
+const char *mz_error(int err);
1189
+
1190
+// Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset of zlib that miniz.c supports.
1191
+// Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project.
1192
+#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
1193
+ typedef unsigned char Byte;
1194
+ typedef unsigned int uInt;
1195
+ typedef mz_ulong uLong;
1196
+ typedef Byte Bytef;
1197
+ typedef uInt uIntf;
1198
+ typedef char charf;
1199
+ typedef int intf;
1200
+ typedef void *voidpf;
1201
+ typedef uLong uLongf;
1202
+ typedef void *voidp;
1203
+ typedef void *const voidpc;
1204
+ #define Z_NULL 0
1205
+ #define Z_NO_FLUSH MZ_NO_FLUSH
1206
+ #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
1207
+ #define Z_SYNC_FLUSH MZ_SYNC_FLUSH
1208
+ #define Z_FULL_FLUSH MZ_FULL_FLUSH
1209
+ #define Z_FINISH MZ_FINISH
1210
+ #define Z_BLOCK MZ_BLOCK
1211
+ #define Z_OK MZ_OK
1212
+ #define Z_STREAM_END MZ_STREAM_END
1213
+ #define Z_NEED_DICT MZ_NEED_DICT
1214
+ #define Z_ERRNO MZ_ERRNO
1215
+ #define Z_STREAM_ERROR MZ_STREAM_ERROR
1216
+ #define Z_DATA_ERROR MZ_DATA_ERROR
1217
+ #define Z_MEM_ERROR MZ_MEM_ERROR
1218
+ #define Z_BUF_ERROR MZ_BUF_ERROR
1219
+ #define Z_VERSION_ERROR MZ_VERSION_ERROR
1220
+ #define Z_PARAM_ERROR MZ_PARAM_ERROR
1221
+ #define Z_NO_COMPRESSION MZ_NO_COMPRESSION
1222
+ #define Z_BEST_SPEED MZ_BEST_SPEED
1223
+ #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION
1224
+ #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
1225
+ #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY
1226
+ #define Z_FILTERED MZ_FILTERED
1227
+ #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY
1228
+ #define Z_RLE MZ_RLE
1229
+ #define Z_FIXED MZ_FIXED
1230
+ #define Z_DEFLATED MZ_DEFLATED
1231
+ #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
1232
+ #define alloc_func mz_alloc_func
1233
+ #define free_func mz_free_func
1234
+ #define internal_state mz_internal_state
1235
+ #define z_stream mz_stream
1236
+ #define deflateInit mz_deflateInit
1237
+ #define deflateInit2 mz_deflateInit2
1238
+ #define deflateReset mz_deflateReset
1239
+ #define deflate mz_deflate
1240
+ #define deflateEnd mz_deflateEnd
1241
+ #define deflateBound mz_deflateBound
1242
+ #define compress mz_compress
1243
+ #define compress2 mz_compress2
1244
+ #define compressBound mz_compressBound
1245
+ #define inflateInit mz_inflateInit
1246
+ #define inflateInit2 mz_inflateInit2
1247
+ #define inflate mz_inflate
1248
+ #define inflateEnd mz_inflateEnd
1249
+ #define uncompress mz_uncompress
1250
+ #define crc32 mz_crc32
1251
+ #define adler32 mz_adler32
1252
+ #define MAX_WBITS 15
1253
+ #define MAX_MEM_LEVEL 9
1254
+ #define zError mz_error
1255
+ #define ZLIB_VERSION MZ_VERSION
1256
+ #define ZLIB_VERNUM MZ_VERNUM
1257
+ #define ZLIB_VER_MAJOR MZ_VER_MAJOR
1258
+ #define ZLIB_VER_MINOR MZ_VER_MINOR
1259
+ #define ZLIB_VER_REVISION MZ_VER_REVISION
1260
+ #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
1261
+ #define zlibVersion mz_version
1262
+ #define zlib_version mz_version()
1263
+#endif // #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
1264
+
1265
+#endif // MINIZ_NO_ZLIB_APIS
1266
+
1267
+// ------------------- Types and macros
1268
+
1269
+typedef unsigned char mz_uint8;
1270
+typedef signed short mz_int16;
1271
+typedef unsigned short mz_uint16;
1272
+typedef unsigned int mz_uint32;
1273
+typedef unsigned int mz_uint;
1274
+typedef long long mz_int64;
1275
+typedef unsigned long long mz_uint64;
1276
+typedef int mz_bool;
1277
+
1278
+#define MZ_FALSE (0)
1279
+#define MZ_TRUE (1)
1280
+
1281
+// An attempt to work around MSVC's spammy "warning C4127: conditional expression is constant" message.
1282
+#ifdef _MSC_VER
1283
+ #define MZ_MACRO_END while (0, 0)
1284
+#else
1285
+ #define MZ_MACRO_END while (0)
1286
+#endif
1287
+
1288
+// ------------------- ZIP archive reading/writing
1289
+
1290
+#ifndef MINIZ_NO_ARCHIVE_APIS
1291
+
1292
+enum
1293
+{
1294
+ MZ_ZIP_MAX_IO_BUF_SIZE = 64*1024,
1295
+ MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 260,
1296
+ MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 256
1297
+};
1298
+
1299
+typedef struct
1300
+{
1301
+ mz_uint32 m_file_index;
1302
+ mz_uint32 m_central_dir_ofs;
1303
+ mz_uint16 m_version_made_by;
1304
+ mz_uint16 m_version_needed;
1305
+ mz_uint16 m_bit_flag;
1306
+ mz_uint16 m_method;
1307
+#ifndef MINIZ_NO_TIME
1308
+ time_t m_time;
1309
+#endif
1310
+ mz_uint32 m_crc32;
1311
+ mz_uint64 m_comp_size;
1312
+ mz_uint64 m_uncomp_size;
1313
+ mz_uint16 m_internal_attr;
1314
+ mz_uint32 m_external_attr;
1315
+ mz_uint64 m_local_header_ofs;
1316
+ mz_uint32 m_comment_size;
1317
+ char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
1318
+ char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
1319
+} mz_zip_archive_file_stat;
1320
+
1321
+typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
1322
+typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
1323
+
1324
+struct mz_zip_internal_state_tag;
1325
+typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
1326
+
1327
+typedef enum
1328
+{
1329
+ MZ_ZIP_MODE_INVALID = 0,
1330
+ MZ_ZIP_MODE_READING = 1,
1331
+ MZ_ZIP_MODE_WRITING = 2,
1332
+ MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
1333
+} mz_zip_mode;
1334
+
1335
+typedef struct mz_zip_archive_tag
1336
+{
1337
+ mz_uint64 m_archive_size;
1338
+ mz_uint64 m_central_directory_file_ofs;
1339
+ mz_uint m_total_files;
1340
+ mz_zip_mode m_zip_mode;
1341
+
1342
+ mz_uint m_file_offset_alignment;
1343
+
1344
+ mz_alloc_func m_pAlloc;
1345
+ mz_free_func m_pFree;
1346
+ mz_realloc_func m_pRealloc;
1347
+ void *m_pAlloc_opaque;
1348
+
1349
+ mz_file_read_func m_pRead;
1350
+ mz_file_write_func m_pWrite;
1351
+ void *m_pIO_opaque;
1352
+
1353
+ mz_zip_internal_state *m_pState;
1354
+
1355
+} mz_zip_archive;
1356
+
1357
+typedef enum
1358
+{
1359
+ MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
1360
+ MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
1361
+ MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
1362
+ MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800
1363
+} mz_zip_flags;
1364
+
1365
+// ZIP archive reading
1366
+
1367
+// Inits a ZIP archive reader.
1368
+// These functions read and validate the archive's central directory.
1369
+mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint32 flags);
1370
+mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint32 flags);
1371
+
1372
+#ifndef MINIZ_NO_STDIO
1373
+mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
1374
+#endif
1375
+
1376
+// Returns the total number of files in the archive.
1377
+mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
1378
+
1379
+// Returns detailed information about an archive file entry.
1380
+mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
1381
+
1382
+// Determines if an archive file entry is a directory entry.
1383
+mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
1384
+mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
1385
+
1386
+// Retrieves the filename of an archive file entry.
1387
+// Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename.
1388
+mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
1389
+
1390
+// Attempts to locates a file in the archive's central directory.
1391
+// Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH
1392
+// Returns -1 if the file cannot be found.
1393
+int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
1394
+
1395
+// Extracts a archive file to a memory buffer using no memory allocation.
1396
+mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
1397
+mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
1398
+
1399
+// Extracts a archive file to a memory buffer.
1400
+mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags);
1401
+mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags);
1402
+
1403
+// Extracts a archive file to a dynamically allocated heap buffer.
1404
+void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
1405
+void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
1406
+
1407
+// Extracts a archive file using a callback function to output the file's data.
1408
+mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
1409
+mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
1410
+
1411
+#ifndef MINIZ_NO_STDIO
1412
+// Extracts a archive file to a disk file and sets its last accessed and modified times.
1413
+// This function only extracts files, not archive directory records.
1414
+mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
1415
+mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
1416
+#endif
1417
+
1418
+// Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used.
1419
+mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
1420
+
1421
+// ZIP archive writing
1422
+
1423
+#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
1424
+
1425
+// Inits a ZIP archive writer.
1426
+mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
1427
+mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
1428
+
1429
+#ifndef MINIZ_NO_STDIO
1430
+mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
1431
+#endif
1432
+
1433
+// Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive.
1434
+// For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for writing. If the file can't be reopened, mz_zip_reader_end() will be called.
1435
+// For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which defaults to realloc unless you've overridden it).
1436
+// Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL.
1437
+// Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before
1438
+// the archive is finalized the file's central directory will be hosed.
1439
+mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
1440
+
1441
+// Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive.
1442
+// To add a directory entry, call this method with an archive name ending in a forwardslash with empty buffer.
1443
+// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
1444
+mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags);
1445
+mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
1446
+
1447
+#ifndef MINIZ_NO_STDIO
1448
+// Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive.
1449
+// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
1450
+mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
1451
+#endif
1452
+
1453
+// Adds a file to an archive by fully cloning the data from another archive.
1454
+// This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data, and comment fields.
1455
+mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint file_index);
1456
+
1457
+// Finalizes the archive by writing the central directory records followed by the end of central directory record.
1458
+// After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end().
1459
+// An archive must be manually finalized by calling this function for it to be valid.
1460
+mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
1461
+mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **pBuf, size_t *pSize);
1462
+
1463
+// Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used.
1464
+// Note for the archive to be valid, it must have been finalized before ending.
1465
+mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
1466
+
1467
+// Misc. high-level helper functions:
1468
+
1469
+// mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive.
1470
+// level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
1471
+mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
1472
+
1473
+// Reads a single file from an archive into a heap block.
1474
+// Returns NULL on failure.
1475
+void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint zip_flags);
1476
+
1477
+#endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
1478
+
1479
+#endif // #ifndef MINIZ_NO_ARCHIVE_APIS
1480
+
1481
+// ------------------- Low-level Decompression API Definitions
1482
+
1483
+// Decompression flags used by tinfl_decompress().
1484
+// TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream.
1485
+// TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input.
1486
+// TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB).
1487
+// TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes.
1488
+enum
1489
+{
1490
+ TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
1491
+ TINFL_FLAG_HAS_MORE_INPUT = 2,
1492
+ TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
1493
+ TINFL_FLAG_COMPUTE_ADLER32 = 8
1494
+};
1495
+
1496
+// High level decompression functions:
1497
+// tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc().
1498
+// On entry:
1499
+// pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress.
1500
+// On return:
1501
+// Function returns a pointer to the decompressed data, or NULL on failure.
1502
+// *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data.
1503
+// The caller must call mz_free() on the returned block when it's no longer needed.
1504
+void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
1505
+
1506
+// tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory.
1507
+// Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success.
1508
+#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
1509
+size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
1510
+
1511
+// tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer.
1512
+// Returns 1 on success or 0 on failure.
1513
+typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
1514
+int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
1515
+
1516
+struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor;
1517
+
1518
+// Max size of LZ dictionary.
1519
+#define TINFL_LZ_DICT_SIZE 32768
1520
+
1521
+// Return status.
1522
+typedef enum
1523
+{
1524
+ TINFL_STATUS_BAD_PARAM = -3,
1525
+ TINFL_STATUS_ADLER32_MISMATCH = -2,
1526
+ TINFL_STATUS_FAILED = -1,
1527
+ TINFL_STATUS_DONE = 0,
1528
+ TINFL_STATUS_NEEDS_MORE_INPUT = 1,
1529
+ TINFL_STATUS_HAS_MORE_OUTPUT = 2
1530
+} tinfl_status;
1531
+
1532
+// Initializes the decompressor to its initial state.
1533
+#define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END
1534
+#define tinfl_get_adler32(r) (r)->m_check_adler32
1535
+
1536
+// Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability.
1537
+// This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output.
1538
+tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags);
1539
+
1540
+// Internal/private bits follow.
1541
+enum
1542
+{
1543
+ TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19,
1544
+ TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
1545
+};
1546
+
1547
+typedef struct
1548
+{
1549
+ mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
1550
+ mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
1551
+} tinfl_huff_table;
1552
+
1553
+#if MINIZ_HAS_64BIT_REGISTERS
1554
+ #define TINFL_USE_64BIT_BITBUF 1
1555
+#endif
1556
+
1557
+#if TINFL_USE_64BIT_BITBUF
1558
+ typedef mz_uint64 tinfl_bit_buf_t;
1559
+ #define TINFL_BITBUF_SIZE (64)
1560
+#else
1561
+ typedef mz_uint32 tinfl_bit_buf_t;
1562
+ #define TINFL_BITBUF_SIZE (32)
1563
+#endif
1564
+
1565
+struct tinfl_decompressor_tag
1566
+{
1567
+ mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES];
1568
+ tinfl_bit_buf_t m_bit_buf;
1569
+ size_t m_dist_from_out_buf_start;
1570
+ tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
1571
+ mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
1572
+};
1573
+
1574
+// ------------------- Low-level Compression API Definitions
1575
+
1576
+// Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently).
1577
+#define TDEFL_LESS_MEMORY 0
1578
+
1579
+// tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search):
1580
+// TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression).
1581
+enum
1582
+{
1583
+ TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF
1584
+};
1585
+
1586
+// TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data.
1587
+// TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers).
1588
+// TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing.
1589
+// TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory).
1590
+// TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1)
1591
+// TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled.
1592
+// TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables.
1593
+// TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks.
1594
+// The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK).
1595
+enum
1596
+{
1597
+ TDEFL_WRITE_ZLIB_HEADER = 0x01000,
1598
+ TDEFL_COMPUTE_ADLER32 = 0x02000,
1599
+ TDEFL_GREEDY_PARSING_FLAG = 0x04000,
1600
+ TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
1601
+ TDEFL_RLE_MATCHES = 0x10000,
1602
+ TDEFL_FILTER_MATCHES = 0x20000,
1603
+ TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000,
1604
+ TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
1605
+};
1606
+
1607
+// High level compression functions:
1608
+// tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc().
1609
+// On entry:
1610
+// pSrc_buf, src_buf_len: Pointer and size of source block to compress.
1611
+// flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression.
1612
+// On return:
1613
+// Function returns a pointer to the compressed data, or NULL on failure.
1614
+// *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data.
1615
+// The caller must free() the returned block when it's no longer needed.
1616
+void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
1617
+
1618
+// tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory.
1619
+// Returns 0 on failure.
1620
+size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
1621
+
1622
+// Compresses an image to a compressed PNG file in memory.
1623
+// On entry:
1624
+// pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4.
1625
+// The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory.
1626
+// level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc. or a decent default is MZ_DEFAULT_LEVEL
1627
+// If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps).
1628
+// On return:
1629
+// Function returns a pointer to the compressed data, or NULL on failure.
1630
+// *pLen_out will be set to the size of the PNG image file.
1631
+// The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
1632
+void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip);
1633
+void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
1634
+
1635
+// Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
1636
+typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
1637
+
1638
+// tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally.
1639
+mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
1640
+
1641
+enum { TDEFL_MAX_HUFF_TABLES = 3, TDEFL_MAX_HUFF_SYMBOLS_0 = 288, TDEFL_MAX_HUFF_SYMBOLS_1 = 32, TDEFL_MAX_HUFF_SYMBOLS_2 = 19, TDEFL_LZ_DICT_SIZE = 32768, TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, TDEFL_MIN_MATCH_LEN = 3, TDEFL_MAX_MATCH_LEN = 258 };
1642
+
1643
+// TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes).
1644
+#if TDEFL_LESS_MEMORY
1645
+enum { TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 12, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
1646
+#else
1647
+enum { TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 15, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
1648
+#endif
1649
+
1650
+// The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions.
1651
+typedef enum
1652
+{
1653
+ TDEFL_STATUS_BAD_PARAM = -2,
1654
+ TDEFL_STATUS_PUT_BUF_FAILED = -1,
1655
+ TDEFL_STATUS_OKAY = 0,
1656
+ TDEFL_STATUS_DONE = 1,
1657
+} tdefl_status;
1658
+
1659
+// Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums
1660
+typedef enum
1661
+{
1662
+ TDEFL_NO_FLUSH = 0,
1663
+ TDEFL_SYNC_FLUSH = 2,
1664
+ TDEFL_FULL_FLUSH = 3,
1665
+ TDEFL_FINISH = 4
1666
+} tdefl_flush;
1667
+
1668
+// tdefl's compression state structure.
1669
+typedef struct
1670
+{
1671
+ tdefl_put_buf_func_ptr m_pPut_buf_func;
1672
+ void *m_pPut_buf_user;
1673
+ mz_uint m_flags, m_max_probes[2];
1674
+ int m_greedy_parsing;
1675
+ mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size;
1676
+ mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end;
1677
+ mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer;
1678
+ mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index, m_wants_to_finish;
1679
+ tdefl_status m_prev_return_status;
1680
+ const void *m_pIn_buf;
1681
+ void *m_pOut_buf;
1682
+ size_t *m_pIn_buf_size, *m_pOut_buf_size;
1683
+ tdefl_flush m_flush;
1684
+ const mz_uint8 *m_pSrc;
1685
+ size_t m_src_buf_left, m_out_buf_ofs;
1686
+ mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1];
1687
+ mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
1688
+ mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
1689
+ mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
1690
+ mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE];
1691
+ mz_uint16 m_next[TDEFL_LZ_DICT_SIZE];
1692
+ mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE];
1693
+ mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
1694
+} tdefl_compressor;
1695
+
1696
+// Initializes the compressor.
1697
+// There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory.
1698
+// pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user sh
--- a/src/miniz.h
+++ b/src/miniz.h
@@ -0,0 +1,1698 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/src/miniz.h
+++ b/src/miniz.h
@@ -0,0 +1,1698 @@
1 #ifndef MINIZ_HEADER_INCLUDED
2 #define MINIZ_HEADER_INCLUDED
3
4 #include <stdlib.h>
5
6 // Defines to completely disable specific portions of miniz.c:
7 // If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
8
9 // Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O.
10 #define MINIZ_NO_STDIO
11
12 // If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or
13 // get/set file times, and the C run-time funcs that get/set times won't be called.
14 // The current downside is the times written to your archives will be from 1979.
15 #define MINIZ_NO_TIME
16
17 // Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's.
18 #define MINIZ_NO_ARCHIVE_APIS
19
20 // Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's.
21 #define MINIZ_NO_ARCHIVE_WRITING_APIS
22
23 // Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's.
24 //#define MINIZ_NO_ZLIB_APIS
25
26 // Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib.
27 //#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
28
29 // Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
30 // Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
31 // callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
32 // functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work.
33 //#define MINIZ_NO_MALLOC
34
35 #if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
36 // TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux
37 #define MINIZ_NO_TIME
38 #endif
39
40 #if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
41 #include <time.h>
42 #endif
43
44 #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
45 // MINIZ_X86_OR_X64_CPU is only used to help set the below macros.
46 #define MINIZ_X86_OR_X64_CPU 1
47 #endif
48
49 #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
50 // Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian.
51 #define MINIZ_LITTLE_ENDIAN 1
52 #endif
53
54 #if MINIZ_X86_OR_X64_CPU
55 // Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses.
56 #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
57 #endif
58
59 #if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
60 // Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions).
61 #define MINIZ_HAS_64BIT_REGISTERS 1
62 #endif
63
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67
68 // ------------------- zlib-style API Definitions.
69
70 // For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits!
71 typedef unsigned long mz_ulong;
72
73 // mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap.
74 void mz_free(void *p);
75
76 #define MZ_ADLER32_INIT (1)
77 // mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
78 mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
79
80 #define MZ_CRC32_INIT (0)
81 // mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL.
82 mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
83
84 // Compression strategies.
85 enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 };
86
87 // Method
88 #define MZ_DEFLATED 8
89
90 #ifndef MINIZ_NO_ZLIB_APIS
91
92 // Heap allocation callbacks.
93 // Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long.
94 typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
95 typedef void (*mz_free_func)(void *opaque, void *address);
96 typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
97
98 #define MZ_VERSION "9.1.15"
99 #define MZ_VERNUM 0x91F0
100 #define MZ_VER_MAJOR 9
101 #define MZ_VER_MINOR 1
102 #define MZ_VER_REVISION 15
103 #define MZ_VER_SUBREVISION 0
104
105 // Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs).
106 enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
107
108 // Return status codes. MZ_PARAM_ERROR is non-standard.
109 enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 };
110
111 // Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL.
112 enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 };
113
114 // Window bits
115 #define MZ_DEFAULT_WINDOW_BITS 15
116
117 struct mz_internal_state;
118
119 // Compression/decompression stream struct.
120 typedef struct mz_stream_s
121 {
122 const unsigned char *next_in; // pointer to next byte to read
123 unsigned int avail_in; // number of bytes available at next_in
124 mz_ulong total_in; // total number of bytes consumed so far
125
126 unsigned char *next_out; // pointer to next byte to write
127 unsigned int avail_out; // number of bytes that can be written to next_out
128 mz_ulong total_out; // total number of bytes produced so far
129
130 char *msg; // error msg (unused)
131 struct mz_internal_state *state; // internal state, allocated by zalloc/zfree
132
133 mz_alloc_func zalloc; // optional heap allocation function (defaults to malloc)
134 mz_free_func zfree; // optional heap free function (defaults to free)
135 void *opaque; // heap alloc function user pointer
136
137 int data_type; // data_type (unused)
138 mz_ulong adler; // adler32 of the source or uncompressed data
139 mz_ulong reserved; // not used
140 } mz_stream;
141
142 typedef mz_stream *mz_streamp;
143
144 // Returns the version string of miniz.c.
145 const char *mz_version(void);
146
147 // mz_deflateInit() initializes a compressor with default options:
148 // Parameters:
149 // pStream must point to an initialized mz_stream struct.
150 // level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION].
151 // level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
152 // (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.)
153 // Return values:
154 // MZ_OK on success.
155 // MZ_STREAM_ERROR if the stream is bogus.
156 // MZ_PARAM_ERROR if the input parameters are bogus.
157 // MZ_MEM_ERROR on out of memory.
158 int mz_deflateInit(mz_streamp pStream, int level);
159
160 // mz_deflateInit2() is like mz_deflate(), except with more control:
161 // Additional parameters:
162 // method must be MZ_DEFLATED
163 // window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer)
164 // mem_level must be between [1, 9] (it's checked but ignored by miniz.c)
165 int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
166
167 // Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2().
168 int mz_deflateReset(mz_streamp pStream);
169
170 // mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
171 // Parameters:
172 // pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
173 // flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH.
174 // Return values:
175 // MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full).
176 // MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore.
177 // MZ_STREAM_ERROR if the stream is bogus.
178 // MZ_PARAM_ERROR if one of the parameters is invalid.
179 // MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.)
180 int mz_deflate(mz_streamp pStream, int flush);
181
182 // mz_deflateEnd() deinitializes a compressor:
183 // Return values:
184 // MZ_OK on success.
185 // MZ_STREAM_ERROR if the stream is bogus.
186 int mz_deflateEnd(mz_streamp pStream);
187
188 // mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH.
189 mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
190
191 // Single-call compression functions mz_compress() and mz_compress2():
192 // Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure.
193 int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
194 int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level);
195
196 // mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress().
197 mz_ulong mz_compressBound(mz_ulong source_len);
198
199 // Initializes a decompressor.
200 int mz_inflateInit(mz_streamp pStream);
201
202 // mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer:
203 // window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate).
204 int mz_inflateInit2(mz_streamp pStream, int window_bits);
205
206 // Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible.
207 // Parameters:
208 // pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
209 // flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH.
210 // On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster).
211 // MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data.
212 // Return values:
213 // MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full.
214 // MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified.
215 // MZ_STREAM_ERROR if the stream is bogus.
216 // MZ_DATA_ERROR if the deflate stream is invalid.
217 // MZ_PARAM_ERROR if one of the parameters is invalid.
218 // MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again
219 // with more input data, or with more room in the output buffer (except when using single call decompression, described above).
220 int mz_inflate(mz_streamp pStream, int flush);
221
222 // Deinitializes a decompressor.
223 int mz_inflateEnd(mz_streamp pStream);
224
225 // Single-call decompression.
226 // Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure.
227 int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
228
229 // Returns a string description of the specified error code, or NULL if the error code is invalid.
230 const char *mz_error(int err);
231
232 // Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset of zlib that miniz.c supports.
233 // Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project.
234 #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
235 typedef unsigned char Byte;
236 typedef unsigned int uInt;
237 typedef mz_ulong uLong;
238 typedef Byte Bytef;
239 typedef uInt uIntf;
240 typedef char charf;
241 typedef int intf;
242 typedef void *voidpf;
243 typedef uLong uLongf;
244 typedef void *voidp;
245 typedef void *const voidpc;
246 #define Z_NULL 0
247 #define Z_NO_FLUSH MZ_NO_FLUSH
248 #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
249 #define Z_SYNC_FLUSH MZ_SYNC_FLUSH
250 #define Z_FULL_FLUSH MZ_FULL_FLUSH
251 #define Z_FINISH MZ_FINISH
252 #define Z_BLOCK MZ_BLOCK
253 #define Z_OK MZ_OK
254 #define Z_STREAM_END MZ_STREAM_END
255 #define Z_NEED_DICT MZ_NEED_DICT
256 #define Z_ERRNO MZ_ERRNO
257 #define Z_STREAM_ERROR MZ_STREAM_ERROR
258 #define Z_DATA_ERROR MZ_DATA_ERROR
259 #define Z_MEM_ERROR MZ_MEM_ERROR
260 #define Z_BUF_ERROR MZ_BUF_ERROR
261 #define Z_VERSION_ERROR MZ_VERSION_ERROR
262 #define Z_PARAM_ERROR MZ_PARAM_ERROR
263 #define Z_NO_COMPRESSION MZ_NO_COMPRESSION
264 #define Z_BEST_SPEED MZ_BEST_SPEED
265 #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION
266 #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
267 #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY
268 #define Z_FILTERED MZ_FILTERED
269 #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY
270 #define Z_RLE MZ_RLE
271 #define Z_FIXED MZ_FIXED
272 #define Z_DEFLATED MZ_DEFLATED
273 #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
274 #define alloc_func mz_alloc_func
275 #define free_func mz_free_func
276 #define internal_state mz_internal_state
277 #define z_stream mz_stream
278 #define deflateInit mz_deflateInit
279 #define deflateInit2 mz_deflateInit2
280 #define deflateReset mz_deflateReset
281 #define deflate mz_deflate
282 #define deflateEnd mz_deflateEnd
283 #define deflateBound mz_deflateBound
284 #define compress mz_compress
285 #define compress2 mz_compress2
286 #define compressBound mz_compressBound
287 #define inflateInit mz_inflateInit
288 #define inflateInit2 mz_inflateInit2
289 #define inflate mz_inflate
290 #define inflateEnd mz_inflateEnd
291 #define uncompress mz_uncompress
292 #define crc32 mz_crc32
293 #define adler32 mz_adler32
294 #define MAX_WBITS 15
295 #define MAX_MEM_LEVEL 9
296 #define zError mz_error
297 #define ZLIB_VERSION MZ_VERSION
298 #define ZLIB_VERNUM MZ_VERNUM
299 #define ZLIB_VER_MAJOR MZ_VER_MAJOR
300 #define ZLIB_VER_MINOR MZ_VER_MINOR
301 #define ZLIB_VER_REVISION MZ_VER_REVISION
302 #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
303 #define zlibVersion mz_version
304 #define zlib_version mz_version()
305 #endif // #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
306
307 #endif // MINIZ_NO_ZLIB_APIS
308
309 // ------------------- Types and macros
310
311 typedef unsigned char mz_uint8;
312 typedef signed short mz_int16;
313 typedef unsigned short mz_uint16;
314 typedef unsigned int mz_uint32;
315 typedef unsigned int mz_uint;
316 typedef long long mz_int64;
317 typedef unsigned long long mz_uint64;
318 typedef int mz_bool;
319
320 #define MZ_FALSE (0)
321 #define MZ_TRUE (1)
322
323 // An attempt to work around MSVC's spammy "warning C4127: conditional expression is constant" message.
324 #ifdef _MSC_VER
325 #define MZ_MACRO_END while (0, 0)
326 #else
327 #define MZ_MACRO_END while (0)
328 #endif
329
330 // ------------------- ZIP archive reading/writing
331
332 #ifndef MINIZ_NO_ARCHIVE_APIS
333
334 enum
335 {
336 MZ_ZIP_MAX_IO_BUF_SIZE = 64*1024,
337 MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 260,
338 MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 256
339 };
340
341 typedef struct
342 {
343 mz_uint32 m_file_index;
344 mz_uint32 m_central_dir_ofs;
345 mz_uint16 m_version_made_by;
346 mz_uint16 m_version_needed;
347 mz_uint16 m_bit_flag;
348 mz_uint16 m_method;
349 #ifndef MINIZ_NO_TIME
350 time_t m_time;
351 #endif
352 mz_uint32 m_crc32;
353 mz_uint64 m_comp_size;
354 mz_uint64 m_uncomp_size;
355 mz_uint16 m_internal_attr;
356 mz_uint32 m_external_attr;
357 mz_uint64 m_local_header_ofs;
358 mz_uint32 m_comment_size;
359 char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
360 char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
361 } mz_zip_archive_file_stat;
362
363 typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
364 typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
365
366 struct mz_zip_internal_state_tag;
367 typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
368
369 typedef enum
370 {
371 MZ_ZIP_MODE_INVALID = 0,
372 MZ_ZIP_MODE_READING = 1,
373 MZ_ZIP_MODE_WRITING = 2,
374 MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
375 } mz_zip_mode;
376
377 typedef struct mz_zip_archive_tag
378 {
379 mz_uint64 m_archive_size;
380 mz_uint64 m_central_directory_file_ofs;
381 mz_uint m_total_files;
382 mz_zip_mode m_zip_mode;
383
384 mz_uint m_file_offset_alignment;
385
386 mz_alloc_func m_pAlloc;
387 mz_free_func m_pFree;
388 mz_realloc_func m_pRealloc;
389 void *m_pAlloc_opaque;
390
391 mz_file_read_func m_pRead;
392 mz_file_write_func m_pWrite;
393 void *m_pIO_opaque;
394
395 mz_zip_internal_state *m_pState;
396
397 } mz_zip_archive;
398
399 typedef enum
400 {
401 MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
402 MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
403 MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
404 MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800
405 } mz_zip_flags;
406
407 // ZIP archive reading
408
409 // Inits a ZIP archive reader.
410 // These functions read and validate the archive's central directory.
411 mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint32 flags);
412 mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint32 flags);
413
414 #ifndef MINIZ_NO_STDIO
415 mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
416 #endif
417
418 // Returns the total number of files in the archive.
419 mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
420
421 // Returns detailed information about an archive file entry.
422 mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
423
424 // Determines if an archive file entry is a directory entry.
425 mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
426 mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
427
428 // Retrieves the filename of an archive file entry.
429 // Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename.
430 mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
431
432 // Attempts to locates a file in the archive's central directory.
433 // Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH
434 // Returns -1 if the file cannot be found.
435 int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
436
437 // Extracts a archive file to a memory buffer using no memory allocation.
438 mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
439 mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
440
441 // Extracts a archive file to a memory buffer.
442 mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags);
443 mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags);
444
445 // Extracts a archive file to a dynamically allocated heap buffer.
446 void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
447 void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
448
449 // Extracts a archive file using a callback function to output the file's data.
450 mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
451 mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
452
453 #ifndef MINIZ_NO_STDIO
454 // Extracts a archive file to a disk file and sets its last accessed and modified times.
455 // This function only extracts files, not archive directory records.
456 mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
457 mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
458 #endif
459
460 // Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used.
461 mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
462
463 // ZIP archive writing
464
465 #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
466
467 // Inits a ZIP archive writer.
468 mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
469 mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
470
471 #ifndef MINIZ_NO_STDIO
472 mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
473 #endif
474
475 // Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive.
476 // For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for writing. If the file can't be reopened, mz_zip_reader_end() will be called.
477 // For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which defaults to realloc unless you've overridden it).
478 // Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL.
479 // Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before
480 // the archive is finalized the file's central directory will be hosed.
481 mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
482
483 // Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive.
484 // To add a directory entry, call this method with an archive name ending in a forwardslash with empty buffer.
485 // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
486 mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags);
487 mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
488
489 #ifndef MINIZ_NO_STDIO
490 // Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive.
491 // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
492 mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
493 #endif
494
495 // Adds a file to an archive by fully cloning the data from another archive.
496 // This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data, and comment fields.
497 mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint file_index);
498
499 // Finalizes the archive by writing the central directory records followed by the end of central directory record.
500 // After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end().
501 // An archive must be manually finalized by calling this function for it to be valid.
502 mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
503 mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **pBuf, size_t *pSize);
504
505 // Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used.
506 // Note for the archive to be valid, it must have been finalized before ending.
507 mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
508
509 // Misc. high-level helper functions:
510
511 // mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive.
512 // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
513 mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
514
515 // Reads a single file from an archive into a heap block.
516 // Returns NULL on failure.
517 void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint zip_flags);
518
519 #endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
520
521 #endif // #ifndef MINIZ_NO_ARCHIVE_APIS
522
523 // ------------------- Low-level Decompression API Definitions
524
525 // Decompression flags used by tinfl_decompress().
526 // TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream.
527 // TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input.
528 // TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB).
529 // TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes.
530 enum
531 {
532 TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
533 TINFL_FLAG_HAS_MORE_INPUT = 2,
534 TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
535 TINFL_FLAG_COMPUTE_ADLER32 = 8
536 };
537
538 // High level decompression functions:
539 // tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc().
540 // On entry:
541 // pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress.
542 // On return:
543 // Function returns a pointer to the decompressed data, or NULL on failure.
544 // *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data.
545 // The caller must call mz_free() on the returned block when it's no longer needed.
546 void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
547
548 // tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory.
549 // Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success.
550 #define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
551 size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
552
553 // tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer.
554 // Returns 1 on success or 0 on failure.
555 typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
556 int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
557
558 struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor;
559
560 // Max size of LZ dictionary.
561 #define TINFL_LZ_DICT_SIZE 32768
562
563 // Return status.
564 typedef enum
565 {
566 TINFL_STATUS_BAD_PARAM = -3,
567 TINFL_STATUS_ADLER32_MISMATCH = -2,
568 TINFL_STATUS_FAILED = -1,
569 TINFL_STATUS_DONE = 0,
570 TINFL_STATUS_NEEDS_MORE_INPUT = 1,
571 TINFL_STATUS_HAS_MORE_OUTPUT = 2
572 } tinfl_status;
573
574 // Initializes the decompressor to its initial state.
575 #define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END
576 #define tinfl_get_adler32(r) (r)->m_check_adler32
577
578 // Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability.
579 // This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output.
580 tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags);
581
582 // Internal/private bits follow.
583 enum
584 {
585 TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19,
586 TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
587 };
588
589 typedef struct
590 {
591 mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
592 mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
593 } tinfl_huff_table;
594
595 #if MINIZ_HAS_64BIT_REGISTERS
596 #define TINFL_USE_64BIT_BITBUF 1
597 #endif
598
599 #if TINFL_USE_64BIT_BITBUF
600 typedef mz_uint64 tinfl_bit_buf_t;
601 #define TINFL_BITBUF_SIZE (64)
602 #else
603 typedef mz_uint32 tinfl_bit_buf_t;
604 #define TINFL_BITBUF_SIZE (32)
605 #endif
606
607 struct tinfl_decompressor_tag
608 {
609 mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES];
610 tinfl_bit_buf_t m_bit_buf;
611 size_t m_dist_from_out_buf_start;
612 tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
613 mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
614 };
615
616 // ------------------- Low-level Compression API Definitions
617
618 // Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently).
619 #define TDEFL_LESS_MEMORY 0
620
621 // tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search):
622 // TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression).
623 enum
624 {
625 TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF
626 };
627
628 // TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data.
629 // TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers).
630 // TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing.
631 // TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory).
632 // TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1)
633 // TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled.
634 // TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables.
635 // TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks.
636 // The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK).
637 enum
638 {
639 TDEFL_WRITE_ZLIB_HEADER = 0x01000,
640 TDEFL_COMPUTE_ADLER32 = 0x02000,
641 TDEFL_GREEDY_PARSING_FLAG = 0x04000,
642 TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
643 TDEFL_RLE_MATCHES = 0x10000,
644 TDEFL_FILTER_MATCHES = 0x20000,
645 TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000,
646 TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
647 };
648
649 // High level compression functions:
650 // tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc().
651 // On entry:
652 // pSrc_buf, src_buf_len: Pointer and size of source block to compress.
653 // flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression.
654 // On return:
655 // Function returns a pointer to the compressed data, or NULL on failure.
656 // *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data.
657 // The caller must free() the returned block when it's no longer needed.
658 void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
659
660 // tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory.
661 // Returns 0 on failure.
662 size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
663
664 // Compresses an image to a compressed PNG file in memory.
665 // On entry:
666 // pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4.
667 // The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory.
668 // level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc. or a decent default is MZ_DEFAULT_LEVEL
669 // If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps).
670 // On return:
671 // Function returns a pointer to the compressed data, or NULL on failure.
672 // *pLen_out will be set to the size of the PNG image file.
673 // The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
674 void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip);
675 void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
676
677 // Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
678 typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
679
680 // tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally.
681 mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
682
683 enum { TDEFL_MAX_HUFF_TABLES = 3, TDEFL_MAX_HUFF_SYMBOLS_0 = 288, TDEFL_MAX_HUFF_SYMBOLS_1 = 32, TDEFL_MAX_HUFF_SYMBOLS_2 = 19, TDEFL_LZ_DICT_SIZE = 32768, TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, TDEFL_MIN_MATCH_LEN = 3, TDEFL_MAX_MATCH_LEN = 258 };
684
685 // TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes).
686 #if TDEFL_LESS_MEMORY
687 enum { TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 12, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
688 #else
689 enum { TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 15, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
690 #endif
691
692 // The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions.
693 typedef enum
694 {
695 TDEFL_STATUS_BAD_PARAM = -2,
696 TDEFL_STATUS_PUT_BUF_FAILED = -1,
697 TDEFL_STATUS_OKAY = 0,
698 TDEFL_STATUS_DONE = 1,
699 } tdefl_status;
700
701 // Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums
702 typedef enum
703 {
704 TDEFL_NO_FLUSH = 0,
705 TDEFL_SYNC_FLUSH = 2,
706 TDEFL_FULL_FLUSH = 3,
707 TDEFL_FINISH = 4
708 } tdefl_flush;
709
710 // tdefl's compression state structure.
711 typedef struct
712 {
713 tdefl_put_buf_func_ptr m_pPut_buf_func;
714 void *m_pPut_buf_user;
715 mz_uint m_flags, m_max_probes[2];
716 int m_greedy_parsing;
717 mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size;
718 mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end;
719 mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer;
720 mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index, m_wants_to_finish;
721 tdefl_status m_prev_return_status;
722 const void *m_pIn_buf;
723 void *m_pOut_buf;
724 size_t *m_pIn_buf_size, *m_pOut_buf_size;
725 tdefl_flush m_flush;
726 const mz_uint8 *m_pSrc;
727 size_t m_src_buf_left, m_out_buf_ofs;
728 mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1];
729 mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
730 mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
731 mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
732 mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE];
733 mz_uint16 m_next[TDEFL_LZ_DICT_SIZE];
734 mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE];
735 mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
736 } tdefl_compressor;
737
738 // Initializes the compressor.
739 // There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory.
740 // pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression.
741 // If pBut_buf_func is NULL the user should always call the tdefl_compress() API.
742 // flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.)
743 tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
744
745 // Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much compressed data to the specified output buffer as possible.
746 tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush);
747
748 // tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr.
749 // tdefl_compress_buffer() always consumes the entire input buffer.
750 tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush);
751
752 tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
753 mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
754
755 // Can't use tdefl_create_comp_flags_from_zip_params if MINIZ_NO_ZLIB_APIS isn't defined, because it uses some of its macros.
756 #ifndef MINIZ_NO_ZLIB_APIS
757 // Create tdefl_compress() flags given zlib-style compression parameters.
758 // level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files)
759 // window_bits may be -15 (raw deflate) or 15 (zlib)
760 // strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED
761 mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
762 #endif // #ifndef MINIZ_NO_ZLIB_APIS
763
764 #ifdef __cplusplus
765 }
766 #endif
767
768 #endif // MINIZ_HEADER_INCLUDED
769
770 #ifndef MINIZ_HEADER_INCLUDED
771 #define MINIZ_HEADER_INCLUDED
772
773 #include <stdlib.h>
774
775 // Defines to completely disable specific portions of miniz.c:
776 // If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
777
778 // Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O.
779 #define MINIZ_NO_STDIO
780
781 // If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or
782 // get/set file times, and the C run-time funcs that get/set times won't be called.
783 // The current downside is the times written to your archives will be from 1979.
784 #define MINIZ_NO_TIME
785
786 // Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's.
787 #define MINIZ_NO_ARCHIVE_APIS
788
789 // Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's.
790 #define MINIZ_NO_ARCHIVE_WRITING_APIS
791
792 // Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's.
793 //#define MINIZ_NO_ZLIB_APIS
794
795 // Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib.
796 //#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
797
798 // Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
799 // Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
800 // callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
801 // functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work.
802 //#define MINIZ_NO_MALLOC
803
804 #if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
805 // TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux
806 #define MINIZ_NO_TIME
807 #endif
808
809 #if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
810 #include <time.h>
811 #endif
812
813 #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
814 // MINIZ_X86_OR_X64_CPU is only used to help set the below macros.
815 #define MINIZ_X86_OR_X64_CPU 1
816 #endif
817
818 #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
819 // Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian.
820 #define MINIZ_LITTLE_ENDIAN 1
821 #endif
822
823 #if MINIZ_X86_OR_X64_CPU
824 // Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses.
825 #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
826 #endif
827
828 #if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
829 // Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions).
830 #define MINIZ_HAS_64BIT_REGISTERS 1
831 #endif
832
833 #ifdef __cplusplus
834 extern "C" {
835 #endif
836
837 // ------------------- zlib-style API Definitions.
838
839 // For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits!
840 typedef unsigned long mz_ulong;
841
842 // mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap.
843 void mz_free(void *p);
844
845 #define MZ_ADLER32_INIT (1)
846 // mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
847 mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
848
849 #define MZ_CRC32_INIT (0)
850 // mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL.
851 mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
852
853 // Compression strategies.
854 enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 };
855
856 // Method
857 #define MZ_DEFLATED 8
858
859 #ifndef MINIZ_NO_ZLIB_APIS
860
861 // Heap allocation callbacks.
862 // Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long.
863 typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
864 typedef void (*mz_free_func)(void *opaque, void *address);
865 typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
866
867 #define MZ_VERSION "9.1.15"
868 #define MZ_VERNUM 0x91F0
869 #define MZ_VER_MAJOR 9
870 #define MZ_VER_MINOR 1
871 #define MZ_VER_REVISION 15
872 #define MZ_VER_SUBREVISION 0
873
874 // Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs).
875 enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
876
877 // Return status codes. MZ_PARAM_ERROR is non-standard.
878 enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 };
879
880 // Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL.
881 enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 };
882
883 // Window bits
884 #define MZ_DEFAULT_WINDOW_BITS 15
885
886 struct mz_internal_state;
887
888 // Compression/decompression stream struct.
889 typedef struct mz_stream_s
890 {
891 const unsigned char *next_in; // pointer to next byte to read
892 unsigned int avail_in; // number of bytes available at next_in
893 mz_ulong total_in; // total number of bytes consumed so far
894
895 unsigned char *next_out; // pointer to next byte to write
896 unsigned int avail_out; // number of bytes that can be written to next_out
897 mz_ulong total_out; // total number of bytes produced so far
898
899 char *msg; // error msg (unused)
900 struct mz_internal_state *state; // internal state, allocated by zalloc/zfree
901
902 mz_alloc_func zalloc; // optional heap allocation function (defaults to malloc)
903 mz_free_func zfree; // optional heap free function (defaults to free)
904 void *opaque; // heap alloc function user pointer
905
906 int data_type; // data_type (unused)
907 mz_ulong adler; // adler32 of the source or uncompressed data
908 mz_ulong reserved; // not used
909 } mz_stream;
910
911 typedef mz_stream *mz_streamp;
912
913 // Returns the version string of miniz.c.
914 const char *mz_version(void);
915
916 // mz_deflateInit() initializes a compressor with default options:
917 // Parameters:
918 // pStream must point to an initialized mz_stream struct.
919 // level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION].
920 // level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
921 // (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.)
922 // Return values:
923 // MZ_OK on success.
924 // MZ_STREAM_ERROR if the stream is bogus.
925 // MZ_PARAM_ERROR if the input parameters are bogus.
926 // MZ_MEM_ERROR on out of memory.
927 int mz_deflateInit(mz_streamp pStream, int level);
928
929 // mz_deflateInit2() is like mz_deflate(), except with more control:
930 // Additional parameters:
931 // method must be MZ_DEFLATED
932 // window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer)
933 // mem_level must be between [1, 9] (it's checked but ignored by miniz.c)
934 int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
935
936 // Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2().
937 int mz_deflateReset(mz_streamp pStream);
938
939 // mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
940 // Parameters:
941 // pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
942 // flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH.
943 // Return values:
944 // MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full).
945 // MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore.
946 // MZ_STREAM_ERROR if the stream is bogus.
947 // MZ_PARAM_ERROR if one of the parameters is invalid.
948 // MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.)
949 int mz_deflate(mz_streamp pStream, int flush);
950
951 // mz_deflateEnd() deinitializes a compressor:
952 // Return values:
953 // MZ_OK on success.
954 // MZ_STREAM_ERROR if the stream is bogus.
955 int mz_deflateEnd(mz_streamp pStream);
956
957 // mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH.
958 mz_u
959 #ifndef MINIZ_HEADER_INCLUDED
960 #define MINIZ_HEADER_INCLUDED
961
962 #include <stdlib.h>
963
964 // Defines to completely disable specific portions of miniz.c:
965 // If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
966
967 // Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O.
968 #define MINIZ_NO_STDIO
969
970 // If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or
971 // get/set file times, and the C run-time funcs that get/set times won't be called.
972 // The current downside is the times written to your archives will be from 1979.
973 #define MINIZ_NO_TIME
974
975 // Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's.
976 #define MINIZ_NO_ARCHIVE_APIS
977
978 // Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's.
979 #define MINIZ_NO_ARCHIVE_WRITING_APIS
980
981 // Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's.
982 //#define MINIZ_NO_ZLIB_APIS
983
984 // Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib.
985 //#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
986
987 // Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
988 // Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
989 // callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
990 // functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work.
991 //#define MINIZ_NO_MALLOC
992
993 #if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
994 // TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux
995 #define MINIZ_NO_TIME
996 #endif
997
998 #if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
999 #include <time.h>
1000 #endif
1001
1002 #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
1003 // MINIZ_X86_OR_X64_CPU is only used to help set the below macros.
1004 #define MINIZ_X86_OR_X64_CPU 1
1005 #endif
1006
1007 #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
1008 // Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian.
1009 #define MINIZ_LITTLE_ENDIAN 1
1010 #endif
1011
1012 #if MINIZ_X86_OR_X64_CPU
1013 // Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses.
1014 #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
1015 #endif
1016
1017 #if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
1018 // Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions).
1019 #define MINIZ_HAS_64BIT_REGISTERS 1
1020 #endif
1021
1022 #ifdef __cplusplus
1023 extern "C" {
1024 #endif
1025
1026 // ------------------- zlib-style API Definitions.
1027
1028 // For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits!
1029 typedef unsigned long mz_ulong;
1030
1031 // mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap.
1032 void mz_free(void *p);
1033
1034 #define MZ_ADLER32_INIT (1)
1035 // mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
1036 mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
1037
1038 #define MZ_CRC32_INIT (0)
1039 // mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL.
1040 mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
1041
1042 // Compression strategies.
1043 enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 };
1044
1045 // Method
1046 #define MZ_DEFLATED 8
1047
1048 #ifndef MINIZ_NO_ZLIB_APIS
1049
1050 // Heap allocation callbacks.
1051 // Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long.
1052 typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
1053 typedef void (*mz_free_func)(void *opaque, void *address);
1054 typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
1055
1056 #define MZ_VERSION "9.1.15"
1057 #define MZ_VERNUM 0x91F0
1058 #define MZ_VER_MAJOR 9
1059 #define MZ_VER_MINOR 1
1060 #define MZ_VER_REVISION 15
1061 #define MZ_VER_SUBREVISION 0
1062
1063 // Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs).
1064 enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
1065
1066 // Return status codes. MZ_PARAM_ERROR is non-standard.
1067 enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 };
1068
1069 // Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL.
1070 enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 };
1071
1072 // Window bits
1073 #define MZ_DEFAULT_WINDOW_BITS 15
1074
1075 struct mz_internal_state;
1076
1077 // Compression/decompression stream struct.
1078 typedef struct mz_stream_s
1079 {
1080 const unsigned char *next_in; // pointer to next byte to read
1081 unsigned int avail_in; // number of bytes available at next_in
1082 mz_ulong total_in; // total number of bytes consumed so far
1083
1084 unsigned char *next_out; // pointer to next byte to write
1085 unsigned int avail_out; // number of bytes that can be written to next_out
1086 mz_ulong total_out; // total number of bytes produced so far
1087
1088 char *msg; // error msg (unused)
1089 struct mz_internal_state *state; // internal state, allocated by zalloc/zfree
1090
1091 mz_alloc_func zalloc; // optional heap allocation function (defaults to malloc)
1092 mz_free_func zfree; // optional heap free function (defaults to free)
1093 void *opaque; // heap alloc function user pointer
1094
1095 int data_type; // data_type (unused)
1096 mz_ulong adler; // adler32 of the source or uncompressed data
1097 mz_ulong reserved; // not used
1098 } mz_stream;
1099
1100 typedef mz_stream *mz_streamp;
1101
1102 // Returns the version string of miniz.c.
1103 const char *mz_version(void);
1104
1105 // mz_deflateInit() initializes a compressor with default options:
1106 // Parameters:
1107 // pStream must point to an initialized mz_stream struct.
1108 // level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION].
1109 // level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
1110 // (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.)
1111 // Return values:
1112 // MZ_OK on success.
1113 // MZ_STREAM_ERROR if the stream is bogus.
1114 // MZ_PARAM_ERROR if the input parameters are bogus.
1115 // MZ_MEM_ERROR on out of memory.
1116 int mz_deflateInit(mz_streamp pStream, int level);
1117
1118 // mz_deflateInit2() is like mz_deflate(), except with more control:
1119 // Additional parameters:
1120 // method must be MZ_DEFLATED
1121 // window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer)
1122 // mem_level must be between [1, 9] (it's checked but ignored by miniz.c)
1123 int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
1124
1125 // Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2().
1126 int mz_deflateReset(mz_streamp pStream);
1127
1128 // mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
1129 // Parameters:
1130 // pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
1131 // flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH.
1132 // Return values:
1133 // MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full).
1134 // MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore.
1135 // MZ_STREAM_ERROR if the stream is bogus.
1136 // MZ_PARAM_ERROR if one of the parameters is invalid.
1137 // MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.)
1138 int mz_deflate(mz_streamp pStream, int flush);
1139
1140 // mz_deflateEnd() deinitializes a compressor:
1141 // Return values:
1142 // MZ_OK on success.
1143 // MZ_STREAM_ERROR if the stream is bogus.
1144 int mz_deflateEnd(mz_streamp pStream);
1145
1146 // mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH.
1147 mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
1148
1149 // Single-call compression functions mz_compress() and mz_compress2():
1150 // Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure.
1151 int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
1152 int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level);
1153
1154 // mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress().
1155 mz_ulong mz_compressBound(mz_ulong source_len);
1156
1157 // Initializes a decompressor.
1158 int mz_inflateInit(mz_streamp pStream);
1159
1160 // mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer:
1161 // window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate).
1162 int mz_inflateInit2(mz_streamp pStream, int window_bits);
1163
1164 // Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible.
1165 // Parameters:
1166 // pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members.
1167 // flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH.
1168 // On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster).
1169 // MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data.
1170 // Return values:
1171 // MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full.
1172 // MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified.
1173 // MZ_STREAM_ERROR if the stream is bogus.
1174 // MZ_DATA_ERROR if the deflate stream is invalid.
1175 // MZ_PARAM_ERROR if one of the parameters is invalid.
1176 // MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again
1177 // with more input data, or with more room in the output buffer (except when using single call decompression, described above).
1178 int mz_inflate(mz_streamp pStream, int flush);
1179
1180 // Deinitializes a decompressor.
1181 int mz_inflateEnd(mz_streamp pStream);
1182
1183 // Single-call decompression.
1184 // Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure.
1185 int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
1186
1187 // Returns a string description of the specified error code, or NULL if the error code is invalid.
1188 const char *mz_error(int err);
1189
1190 // Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset of zlib that miniz.c supports.
1191 // Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project.
1192 #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
1193 typedef unsigned char Byte;
1194 typedef unsigned int uInt;
1195 typedef mz_ulong uLong;
1196 typedef Byte Bytef;
1197 typedef uInt uIntf;
1198 typedef char charf;
1199 typedef int intf;
1200 typedef void *voidpf;
1201 typedef uLong uLongf;
1202 typedef void *voidp;
1203 typedef void *const voidpc;
1204 #define Z_NULL 0
1205 #define Z_NO_FLUSH MZ_NO_FLUSH
1206 #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
1207 #define Z_SYNC_FLUSH MZ_SYNC_FLUSH
1208 #define Z_FULL_FLUSH MZ_FULL_FLUSH
1209 #define Z_FINISH MZ_FINISH
1210 #define Z_BLOCK MZ_BLOCK
1211 #define Z_OK MZ_OK
1212 #define Z_STREAM_END MZ_STREAM_END
1213 #define Z_NEED_DICT MZ_NEED_DICT
1214 #define Z_ERRNO MZ_ERRNO
1215 #define Z_STREAM_ERROR MZ_STREAM_ERROR
1216 #define Z_DATA_ERROR MZ_DATA_ERROR
1217 #define Z_MEM_ERROR MZ_MEM_ERROR
1218 #define Z_BUF_ERROR MZ_BUF_ERROR
1219 #define Z_VERSION_ERROR MZ_VERSION_ERROR
1220 #define Z_PARAM_ERROR MZ_PARAM_ERROR
1221 #define Z_NO_COMPRESSION MZ_NO_COMPRESSION
1222 #define Z_BEST_SPEED MZ_BEST_SPEED
1223 #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION
1224 #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
1225 #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY
1226 #define Z_FILTERED MZ_FILTERED
1227 #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY
1228 #define Z_RLE MZ_RLE
1229 #define Z_FIXED MZ_FIXED
1230 #define Z_DEFLATED MZ_DEFLATED
1231 #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
1232 #define alloc_func mz_alloc_func
1233 #define free_func mz_free_func
1234 #define internal_state mz_internal_state
1235 #define z_stream mz_stream
1236 #define deflateInit mz_deflateInit
1237 #define deflateInit2 mz_deflateInit2
1238 #define deflateReset mz_deflateReset
1239 #define deflate mz_deflate
1240 #define deflateEnd mz_deflateEnd
1241 #define deflateBound mz_deflateBound
1242 #define compress mz_compress
1243 #define compress2 mz_compress2
1244 #define compressBound mz_compressBound
1245 #define inflateInit mz_inflateInit
1246 #define inflateInit2 mz_inflateInit2
1247 #define inflate mz_inflate
1248 #define inflateEnd mz_inflateEnd
1249 #define uncompress mz_uncompress
1250 #define crc32 mz_crc32
1251 #define adler32 mz_adler32
1252 #define MAX_WBITS 15
1253 #define MAX_MEM_LEVEL 9
1254 #define zError mz_error
1255 #define ZLIB_VERSION MZ_VERSION
1256 #define ZLIB_VERNUM MZ_VERNUM
1257 #define ZLIB_VER_MAJOR MZ_VER_MAJOR
1258 #define ZLIB_VER_MINOR MZ_VER_MINOR
1259 #define ZLIB_VER_REVISION MZ_VER_REVISION
1260 #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
1261 #define zlibVersion mz_version
1262 #define zlib_version mz_version()
1263 #endif // #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
1264
1265 #endif // MINIZ_NO_ZLIB_APIS
1266
1267 // ------------------- Types and macros
1268
1269 typedef unsigned char mz_uint8;
1270 typedef signed short mz_int16;
1271 typedef unsigned short mz_uint16;
1272 typedef unsigned int mz_uint32;
1273 typedef unsigned int mz_uint;
1274 typedef long long mz_int64;
1275 typedef unsigned long long mz_uint64;
1276 typedef int mz_bool;
1277
1278 #define MZ_FALSE (0)
1279 #define MZ_TRUE (1)
1280
1281 // An attempt to work around MSVC's spammy "warning C4127: conditional expression is constant" message.
1282 #ifdef _MSC_VER
1283 #define MZ_MACRO_END while (0, 0)
1284 #else
1285 #define MZ_MACRO_END while (0)
1286 #endif
1287
1288 // ------------------- ZIP archive reading/writing
1289
1290 #ifndef MINIZ_NO_ARCHIVE_APIS
1291
1292 enum
1293 {
1294 MZ_ZIP_MAX_IO_BUF_SIZE = 64*1024,
1295 MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 260,
1296 MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 256
1297 };
1298
1299 typedef struct
1300 {
1301 mz_uint32 m_file_index;
1302 mz_uint32 m_central_dir_ofs;
1303 mz_uint16 m_version_made_by;
1304 mz_uint16 m_version_needed;
1305 mz_uint16 m_bit_flag;
1306 mz_uint16 m_method;
1307 #ifndef MINIZ_NO_TIME
1308 time_t m_time;
1309 #endif
1310 mz_uint32 m_crc32;
1311 mz_uint64 m_comp_size;
1312 mz_uint64 m_uncomp_size;
1313 mz_uint16 m_internal_attr;
1314 mz_uint32 m_external_attr;
1315 mz_uint64 m_local_header_ofs;
1316 mz_uint32 m_comment_size;
1317 char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
1318 char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
1319 } mz_zip_archive_file_stat;
1320
1321 typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
1322 typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
1323
1324 struct mz_zip_internal_state_tag;
1325 typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
1326
1327 typedef enum
1328 {
1329 MZ_ZIP_MODE_INVALID = 0,
1330 MZ_ZIP_MODE_READING = 1,
1331 MZ_ZIP_MODE_WRITING = 2,
1332 MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
1333 } mz_zip_mode;
1334
1335 typedef struct mz_zip_archive_tag
1336 {
1337 mz_uint64 m_archive_size;
1338 mz_uint64 m_central_directory_file_ofs;
1339 mz_uint m_total_files;
1340 mz_zip_mode m_zip_mode;
1341
1342 mz_uint m_file_offset_alignment;
1343
1344 mz_alloc_func m_pAlloc;
1345 mz_free_func m_pFree;
1346 mz_realloc_func m_pRealloc;
1347 void *m_pAlloc_opaque;
1348
1349 mz_file_read_func m_pRead;
1350 mz_file_write_func m_pWrite;
1351 void *m_pIO_opaque;
1352
1353 mz_zip_internal_state *m_pState;
1354
1355 } mz_zip_archive;
1356
1357 typedef enum
1358 {
1359 MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
1360 MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
1361 MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
1362 MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800
1363 } mz_zip_flags;
1364
1365 // ZIP archive reading
1366
1367 // Inits a ZIP archive reader.
1368 // These functions read and validate the archive's central directory.
1369 mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint32 flags);
1370 mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint32 flags);
1371
1372 #ifndef MINIZ_NO_STDIO
1373 mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
1374 #endif
1375
1376 // Returns the total number of files in the archive.
1377 mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
1378
1379 // Returns detailed information about an archive file entry.
1380 mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
1381
1382 // Determines if an archive file entry is a directory entry.
1383 mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
1384 mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
1385
1386 // Retrieves the filename of an archive file entry.
1387 // Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename.
1388 mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
1389
1390 // Attempts to locates a file in the archive's central directory.
1391 // Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH
1392 // Returns -1 if the file cannot be found.
1393 int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
1394
1395 // Extracts a archive file to a memory buffer using no memory allocation.
1396 mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
1397 mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
1398
1399 // Extracts a archive file to a memory buffer.
1400 mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags);
1401 mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags);
1402
1403 // Extracts a archive file to a dynamically allocated heap buffer.
1404 void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
1405 void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
1406
1407 // Extracts a archive file using a callback function to output the file's data.
1408 mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
1409 mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
1410
1411 #ifndef MINIZ_NO_STDIO
1412 // Extracts a archive file to a disk file and sets its last accessed and modified times.
1413 // This function only extracts files, not archive directory records.
1414 mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
1415 mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
1416 #endif
1417
1418 // Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used.
1419 mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
1420
1421 // ZIP archive writing
1422
1423 #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
1424
1425 // Inits a ZIP archive writer.
1426 mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
1427 mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
1428
1429 #ifndef MINIZ_NO_STDIO
1430 mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
1431 #endif
1432
1433 // Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive.
1434 // For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for writing. If the file can't be reopened, mz_zip_reader_end() will be called.
1435 // For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which defaults to realloc unless you've overridden it).
1436 // Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL.
1437 // Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before
1438 // the archive is finalized the file's central directory will be hosed.
1439 mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
1440
1441 // Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive.
1442 // To add a directory entry, call this method with an archive name ending in a forwardslash with empty buffer.
1443 // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
1444 mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags);
1445 mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
1446
1447 #ifndef MINIZ_NO_STDIO
1448 // Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive.
1449 // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
1450 mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
1451 #endif
1452
1453 // Adds a file to an archive by fully cloning the data from another archive.
1454 // This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data, and comment fields.
1455 mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint file_index);
1456
1457 // Finalizes the archive by writing the central directory records followed by the end of central directory record.
1458 // After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end().
1459 // An archive must be manually finalized by calling this function for it to be valid.
1460 mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
1461 mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **pBuf, size_t *pSize);
1462
1463 // Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used.
1464 // Note for the archive to be valid, it must have been finalized before ending.
1465 mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
1466
1467 // Misc. high-level helper functions:
1468
1469 // mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive.
1470 // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION.
1471 mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
1472
1473 // Reads a single file from an archive into a heap block.
1474 // Returns NULL on failure.
1475 void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint zip_flags);
1476
1477 #endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
1478
1479 #endif // #ifndef MINIZ_NO_ARCHIVE_APIS
1480
1481 // ------------------- Low-level Decompression API Definitions
1482
1483 // Decompression flags used by tinfl_decompress().
1484 // TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream.
1485 // TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input.
1486 // TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB).
1487 // TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes.
1488 enum
1489 {
1490 TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
1491 TINFL_FLAG_HAS_MORE_INPUT = 2,
1492 TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
1493 TINFL_FLAG_COMPUTE_ADLER32 = 8
1494 };
1495
1496 // High level decompression functions:
1497 // tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc().
1498 // On entry:
1499 // pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress.
1500 // On return:
1501 // Function returns a pointer to the decompressed data, or NULL on failure.
1502 // *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data.
1503 // The caller must call mz_free() on the returned block when it's no longer needed.
1504 void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
1505
1506 // tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory.
1507 // Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success.
1508 #define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
1509 size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
1510
1511 // tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer.
1512 // Returns 1 on success or 0 on failure.
1513 typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
1514 int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
1515
1516 struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor;
1517
1518 // Max size of LZ dictionary.
1519 #define TINFL_LZ_DICT_SIZE 32768
1520
1521 // Return status.
1522 typedef enum
1523 {
1524 TINFL_STATUS_BAD_PARAM = -3,
1525 TINFL_STATUS_ADLER32_MISMATCH = -2,
1526 TINFL_STATUS_FAILED = -1,
1527 TINFL_STATUS_DONE = 0,
1528 TINFL_STATUS_NEEDS_MORE_INPUT = 1,
1529 TINFL_STATUS_HAS_MORE_OUTPUT = 2
1530 } tinfl_status;
1531
1532 // Initializes the decompressor to its initial state.
1533 #define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END
1534 #define tinfl_get_adler32(r) (r)->m_check_adler32
1535
1536 // Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability.
1537 // This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output.
1538 tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags);
1539
1540 // Internal/private bits follow.
1541 enum
1542 {
1543 TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19,
1544 TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
1545 };
1546
1547 typedef struct
1548 {
1549 mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
1550 mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
1551 } tinfl_huff_table;
1552
1553 #if MINIZ_HAS_64BIT_REGISTERS
1554 #define TINFL_USE_64BIT_BITBUF 1
1555 #endif
1556
1557 #if TINFL_USE_64BIT_BITBUF
1558 typedef mz_uint64 tinfl_bit_buf_t;
1559 #define TINFL_BITBUF_SIZE (64)
1560 #else
1561 typedef mz_uint32 tinfl_bit_buf_t;
1562 #define TINFL_BITBUF_SIZE (32)
1563 #endif
1564
1565 struct tinfl_decompressor_tag
1566 {
1567 mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES];
1568 tinfl_bit_buf_t m_bit_buf;
1569 size_t m_dist_from_out_buf_start;
1570 tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
1571 mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
1572 };
1573
1574 // ------------------- Low-level Compression API Definitions
1575
1576 // Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently).
1577 #define TDEFL_LESS_MEMORY 0
1578
1579 // tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search):
1580 // TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression).
1581 enum
1582 {
1583 TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF
1584 };
1585
1586 // TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data.
1587 // TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers).
1588 // TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing.
1589 // TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory).
1590 // TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1)
1591 // TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled.
1592 // TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables.
1593 // TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks.
1594 // The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK).
1595 enum
1596 {
1597 TDEFL_WRITE_ZLIB_HEADER = 0x01000,
1598 TDEFL_COMPUTE_ADLER32 = 0x02000,
1599 TDEFL_GREEDY_PARSING_FLAG = 0x04000,
1600 TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
1601 TDEFL_RLE_MATCHES = 0x10000,
1602 TDEFL_FILTER_MATCHES = 0x20000,
1603 TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000,
1604 TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
1605 };
1606
1607 // High level compression functions:
1608 // tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc().
1609 // On entry:
1610 // pSrc_buf, src_buf_len: Pointer and size of source block to compress.
1611 // flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression.
1612 // On return:
1613 // Function returns a pointer to the compressed data, or NULL on failure.
1614 // *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data.
1615 // The caller must free() the returned block when it's no longer needed.
1616 void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
1617
1618 // tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory.
1619 // Returns 0 on failure.
1620 size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
1621
1622 // Compresses an image to a compressed PNG file in memory.
1623 // On entry:
1624 // pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4.
1625 // The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory.
1626 // level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc. or a decent default is MZ_DEFAULT_LEVEL
1627 // If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps).
1628 // On return:
1629 // Function returns a pointer to the compressed data, or NULL on failure.
1630 // *pLen_out will be set to the size of the PNG image file.
1631 // The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
1632 void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip);
1633 void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
1634
1635 // Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
1636 typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
1637
1638 // tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally.
1639 mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
1640
1641 enum { TDEFL_MAX_HUFF_TABLES = 3, TDEFL_MAX_HUFF_SYMBOLS_0 = 288, TDEFL_MAX_HUFF_SYMBOLS_1 = 32, TDEFL_MAX_HUFF_SYMBOLS_2 = 19, TDEFL_LZ_DICT_SIZE = 32768, TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, TDEFL_MIN_MATCH_LEN = 3, TDEFL_MAX_MATCH_LEN = 258 };
1642
1643 // TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes).
1644 #if TDEFL_LESS_MEMORY
1645 enum { TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 12, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
1646 #else
1647 enum { TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 15, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
1648 #endif
1649
1650 // The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions.
1651 typedef enum
1652 {
1653 TDEFL_STATUS_BAD_PARAM = -2,
1654 TDEFL_STATUS_PUT_BUF_FAILED = -1,
1655 TDEFL_STATUS_OKAY = 0,
1656 TDEFL_STATUS_DONE = 1,
1657 } tdefl_status;
1658
1659 // Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums
1660 typedef enum
1661 {
1662 TDEFL_NO_FLUSH = 0,
1663 TDEFL_SYNC_FLUSH = 2,
1664 TDEFL_FULL_FLUSH = 3,
1665 TDEFL_FINISH = 4
1666 } tdefl_flush;
1667
1668 // tdefl's compression state structure.
1669 typedef struct
1670 {
1671 tdefl_put_buf_func_ptr m_pPut_buf_func;
1672 void *m_pPut_buf_user;
1673 mz_uint m_flags, m_max_probes[2];
1674 int m_greedy_parsing;
1675 mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size;
1676 mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end;
1677 mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer;
1678 mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index, m_wants_to_finish;
1679 tdefl_status m_prev_return_status;
1680 const void *m_pIn_buf;
1681 void *m_pOut_buf;
1682 size_t *m_pIn_buf_size, *m_pOut_buf_size;
1683 tdefl_flush m_flush;
1684 const mz_uint8 *m_pSrc;
1685 size_t m_src_buf_left, m_out_buf_ofs;
1686 mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1];
1687 mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
1688 mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
1689 mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
1690 mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE];
1691 mz_uint16 m_next[TDEFL_LZ_DICT_SIZE];
1692 mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE];
1693 mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
1694 } tdefl_compressor;
1695
1696 // Initializes the compressor.
1697 // There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory.
1698 // pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user sh
D src/zlib.h

No diff available

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button