SavvyUI C++ UI Library
Loading...
Searching...
No Matches
miniz.h
Go to the documentation of this file.
1/* miniz.c 3.0.2 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
2 See "unlicense" statement at the end of this file.
3 Rich Geldreich <richgel99@gmail.com>, last updated Oct. 13, 2013
4 Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
5
6 Most API's defined in miniz.c are optional. For example, to disable the archive related functions just define
7 MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros).
8
9 * Low-level Deflate/Inflate implementation notes:
10
11 Compression: Use the "tdefl" API's. The compressor supports raw, static, and dynamic blocks, lazy or
12 greedy parsing, match length filtering, RLE-only, and Huffman-only streams. It performs and compresses
13 approximately as well as zlib.
14
15 Decompression: Use the "tinfl" API's. The entire decompressor is implemented as a single function
16 coroutine: see tinfl_decompress(). It supports decompression into a 32KB (or larger power of 2) wrapping buffer, or into a memory
17 block large enough to hold the entire file.
18
19 The low-level tdefl/tinfl API's do not make any use of dynamic memory allocation.
20
21 * zlib-style API notes:
22
23 miniz.c implements a fairly large subset of zlib. There's enough functionality present for it to be a drop-in
24 zlib replacement in many apps:
25 The z_stream struct, optional memory allocation callbacks
26 deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound
27 inflateInit/inflateInit2/inflate/inflateReset/inflateEnd
28 compress, compress2, compressBound, uncompress
29 CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines.
30 Supports raw deflate streams or standard zlib streams with adler-32 checking.
31
32 Limitations:
33 The callback API's are not implemented yet. No support for gzip headers or zlib static dictionaries.
34 I've tried to closely emulate zlib's various flavors of stream flushing and return status codes, but
35 there are no guarantees that miniz.c pulls this off perfectly.
36
37 * PNG writing: See the tdefl_write_image_to_png_file_in_memory() function, originally written by
38 Alex Evans. Supports 1-4 bytes/pixel images.
39
40 * ZIP archive API notes:
41
42 The ZIP archive API's where designed with simplicity and efficiency in mind, with just enough abstraction to
43 get the job done with minimal fuss. There are simple API's to retrieve file information, read files from
44 existing archives, create new archives, append new files to existing archives, or clone archive data from
45 one archive to another. It supports archives located in memory or the heap, on disk (using stdio.h),
46 or you can specify custom file read/write callbacks.
47
48 - Archive reading: Just call this function to read a single file from a disk archive:
49
50 void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name,
51 size_t *pSize, mz_uint zip_flags);
52
53 For more complex cases, use the "mz_zip_reader" functions. Upon opening an archive, the entire central
54 directory is located and read as-is into memory, and subsequent file access only occurs when reading individual files.
55
56 - Archives file scanning: The simple way is to use this function to scan a loaded archive for a specific file:
57
58 int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
59
60 The locate operation can optionally check file comments too, which (as one example) can be used to identify
61 multiple versions of the same file in an archive. This function uses a simple linear search through the central
62 directory, so it's not very fast.
63
64 Alternately, you can iterate through all the files in an archive (using mz_zip_reader_get_num_files()) and
65 retrieve detailed info on each file by calling mz_zip_reader_file_stat().
66
67 - Archive creation: Use the "mz_zip_writer" functions. The ZIP writer immediately writes compressed file data
68 to disk and builds an exact image of the central directory in memory. The central directory image is written
69 all at once at the end of the archive file when the archive is finalized.
70
71 The archive writer can optionally align each file's local header and file data to any power of 2 alignment,
72 which can be useful when the archive will be read from optical media. Also, the writer supports placing
73 arbitrary data blobs at the very beginning of ZIP archives. Archives written using either feature are still
74 readable by any ZIP tool.
75
76 - Archive appending: The simple way to add a single file to an archive is to call this function:
77
78 mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name,
79 const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
80
81 The archive will be created if it doesn't already exist, otherwise it'll be appended to.
82 Note the appending is done in-place and is not an atomic operation, so if something goes wrong
83 during the operation it's possible the archive could be left without a central directory (although the local
84 file headers and file data will be fine, so the archive will be recoverable).
85
86 For more complex archive modification scenarios:
87 1. The safest way is to use a mz_zip_reader to read the existing archive, cloning only those bits you want to
88 preserve into a new archive using using the mz_zip_writer_add_from_zip_reader() function (which compiles the
89 compressed file data as-is). When you're done, delete the old archive and rename the newly written archive, and
90 you're done. This is safe but requires a bunch of temporary disk space or heap memory.
91
92 2. Or, you can convert an mz_zip_reader in-place to an mz_zip_writer using mz_zip_writer_init_from_reader(),
93 append new files as needed, then finalize the archive which will write an updated central directory to the
94 original archive. (This is basically what mz_zip_add_mem_to_archive_file_in_place() does.) There's a
95 possibility that the archive's central directory could be lost with this method if anything goes wrong, though.
96
97 - ZIP archive support limitations:
98 No spanning support. Extraction functions can only handle unencrypted, stored or deflated files.
99 Requires streams capable of seeking.
100
101 * This is a header file library, like stb_image.c. To get only a header file, either cut and paste the
102 below header, or create miniz.h, #define MINIZ_HEADER_FILE_ONLY, and then include miniz.c from it.
103
104 * Important: For best perf. be sure to customize the below macros for your target platform:
105 #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
106 #define MINIZ_LITTLE_ENDIAN 1
107 #define MINIZ_HAS_64BIT_REGISTERS 1
108
109 * On platforms using glibc, Be sure to "#define _LARGEFILE64_SOURCE 1" before including miniz.c to ensure miniz
110 uses the 64-bit variants: fopen64(), stat64(), etc. Otherwise you won't be able to process large files
111 (i.e. 32-bit stat() fails for me on files > 0x7FFFFFFF bytes).
112*/
113#pragma once
114
115#include "miniz_export.h"
116
117/* Defines to completely disable specific portions of miniz.c:
118 If all macros here are defined the only functionality remaining will be CRC-32 and adler-32. */
119
120/* Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O. */
121/*#define MINIZ_NO_STDIO */
122
123/* If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or */
124/* get/set file times, and the C run-time funcs that get/set times won't be called. */
125/* The current downside is the times written to your archives will be from 1979. */
126/*#define MINIZ_NO_TIME */
127
128/* Define MINIZ_NO_DEFLATE_APIS to disable all compression API's. */
129/*#define MINIZ_NO_DEFLATE_APIS */
130
131/* Define MINIZ_NO_INFLATE_APIS to disable all decompression API's. */
132/*#define MINIZ_NO_INFLATE_APIS */
133
134/* Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. */
135/*#define MINIZ_NO_ARCHIVE_APIS */
136
137/* Define MINIZ_NO_ARCHIVE_WRITING_APIS to disable all writing related ZIP archive API's. */
138/*#define MINIZ_NO_ARCHIVE_WRITING_APIS */
139
140/* Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's. */
141/*#define MINIZ_NO_ZLIB_APIS */
142
143/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib. */
144/*#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES */
145
146/* Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
147 Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
148 callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
149 functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. */
150/*#define MINIZ_NO_MALLOC */
151
152#ifdef MINIZ_NO_INFLATE_APIS
153#define MINIZ_NO_ARCHIVE_APIS
154#endif
155
156#ifdef MINIZ_NO_DEFLATE_APIS
157#define MINIZ_NO_ARCHIVE_WRITING_APIS
158#endif
159
160#if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
161/* TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux */
162#define MINIZ_NO_TIME
163#endif
164
165#include <stddef.h>
166
167#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
168#include <time.h>
169#endif
170
171#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
172/* MINIZ_X86_OR_X64_CPU is only used to help set the below macros. */
173#define MINIZ_X86_OR_X64_CPU 1
174#else
175#define MINIZ_X86_OR_X64_CPU 0
176#endif
177
178/* Set MINIZ_LITTLE_ENDIAN only if not set */
179#if !defined(MINIZ_LITTLE_ENDIAN)
180#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
181
182#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
183/* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */
184#define MINIZ_LITTLE_ENDIAN 1
185#else
186#define MINIZ_LITTLE_ENDIAN 0
187#endif
188
189#else
190
191#if MINIZ_X86_OR_X64_CPU
192#define MINIZ_LITTLE_ENDIAN 1
193#else
194#define MINIZ_LITTLE_ENDIAN 0
195#endif
196
197#endif
198#endif
199
200/* Using unaligned loads and stores causes errors when using UBSan */
201#if defined(__has_feature)
202#if __has_feature(undefined_behavior_sanitizer)
203#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
204#endif
205#endif
206
207/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES only if not set */
208#if !defined(MINIZ_USE_UNALIGNED_LOADS_AND_STORES)
209#if MINIZ_X86_OR_X64_CPU
210/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses. */
211#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
212#define MINIZ_UNALIGNED_USE_MEMCPY
213#else
214#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
215#endif
216#endif
217
218#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
219/* 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). */
220#define MINIZ_HAS_64BIT_REGISTERS 1
221#else
222#define MINIZ_HAS_64BIT_REGISTERS 0
223#endif
224
225#ifdef __cplusplus
226extern "C"
227{
228#endif
229
230 /* ------------------- zlib-style API Definitions. */
231
232 /* 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! */
233 typedef unsigned long mz_ulong;
234
235 /* 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. */
236 MINIZ_EXPORT void mz_free(void *p);
237
238#define MZ_ADLER32_INIT (1)
239 /* mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL. */
240 MINIZ_EXPORT mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
241
242#define MZ_CRC32_INIT (0)
243 /* mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL. */
244 MINIZ_EXPORT mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
245
246 /* Compression strategies. */
247 enum
248 {
254 };
255
256/* Method */
257#define MZ_DEFLATED 8
258
259 /* Heap allocation callbacks.
260 Note that mz_alloc_func parameter types purposely differ from zlib's: items/size is size_t, not unsigned long. */
261 typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
262 typedef void (*mz_free_func)(void *opaque, void *address);
263 typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
264
265 /* 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. */
266 enum
267 {
274 };
275
276#define MZ_VERSION "11.0.2"
277#define MZ_VERNUM 0xB002
278#define MZ_VER_MAJOR 11
279#define MZ_VER_MINOR 2
280#define MZ_VER_REVISION 0
281#define MZ_VER_SUBREVISION 0
282
283#ifndef MINIZ_NO_ZLIB_APIS
284
285 /* 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). */
286 enum
287 {
294 };
295
296 /* Return status codes. MZ_PARAM_ERROR is non-standard. */
297 enum
298 {
299 MZ_OK = 0,
309 };
310
311/* Window bits */
312#define MZ_DEFAULT_WINDOW_BITS 15
313
314 struct mz_internal_state;
315
316 /* Compression/decompression stream struct. */
317 typedef struct mz_stream_s
318 {
319 const unsigned char *next_in; /* pointer to next byte to read */
320 unsigned int avail_in; /* number of bytes available at next_in */
321 mz_ulong total_in; /* total number of bytes consumed so far */
322
323 unsigned char *next_out; /* pointer to next byte to write */
324 unsigned int avail_out; /* number of bytes that can be written to next_out */
325 mz_ulong total_out; /* total number of bytes produced so far */
326
327 char *msg; /* error msg (unused) */
328 struct mz_internal_state *state; /* internal state, allocated by zalloc/zfree */
329
330 mz_alloc_func zalloc; /* optional heap allocation function (defaults to malloc) */
331 mz_free_func zfree; /* optional heap free function (defaults to free) */
332 void *opaque; /* heap alloc function user pointer */
333
334 int data_type; /* data_type (unused) */
335 mz_ulong adler; /* adler32 of the source or uncompressed data */
336 mz_ulong reserved; /* not used */
338
340
341 /* Returns the version string of miniz.c. */
342 MINIZ_EXPORT const char *mz_version(void);
343
344#ifndef MINIZ_NO_DEFLATE_APIS
345
346 /* mz_deflateInit() initializes a compressor with default options: */
347 /* Parameters: */
348 /* pStream must point to an initialized mz_stream struct. */
349 /* level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION]. */
350 /* level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio. */
351 /* (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.) */
352 /* Return values: */
353 /* MZ_OK on success. */
354 /* MZ_STREAM_ERROR if the stream is bogus. */
355 /* MZ_PARAM_ERROR if the input parameters are bogus. */
356 /* MZ_MEM_ERROR on out of memory. */
357 MINIZ_EXPORT int mz_deflateInit(mz_streamp pStream, int level);
358
359 /* mz_deflateInit2() is like mz_deflate(), except with more control: */
360 /* Additional parameters: */
361 /* method must be MZ_DEFLATED */
362 /* 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) */
363 /* mem_level must be between [1, 9] (it's checked but ignored by miniz.c) */
364 MINIZ_EXPORT int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
365
366 /* Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2(). */
367 MINIZ_EXPORT int mz_deflateReset(mz_streamp pStream);
368
369 /* mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible. */
370 /* Parameters: */
371 /* 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. */
372 /* flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH. */
373 /* Return values: */
374 /* 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). */
375 /* 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. */
376 /* MZ_STREAM_ERROR if the stream is bogus. */
377 /* MZ_PARAM_ERROR if one of the parameters is invalid. */
378 /* 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.) */
379 MINIZ_EXPORT int mz_deflate(mz_streamp pStream, int flush);
380
381 /* mz_deflateEnd() deinitializes a compressor: */
382 /* Return values: */
383 /* MZ_OK on success. */
384 /* MZ_STREAM_ERROR if the stream is bogus. */
385 MINIZ_EXPORT int mz_deflateEnd(mz_streamp pStream);
386
387 /* 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. */
388 MINIZ_EXPORT mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
389
390 /* Single-call compression functions mz_compress() and mz_compress2(): */
391 /* Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure. */
392 MINIZ_EXPORT int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
393 MINIZ_EXPORT int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level);
394
395 /* mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress(). */
396 MINIZ_EXPORT mz_ulong mz_compressBound(mz_ulong source_len);
397
398#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
399
400#ifndef MINIZ_NO_INFLATE_APIS
401
402 /* Initializes a decompressor. */
403 MINIZ_EXPORT int mz_inflateInit(mz_streamp pStream);
404
405 /* 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: */
406 /* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). */
407 MINIZ_EXPORT int mz_inflateInit2(mz_streamp pStream, int window_bits);
408
409 /* Quickly resets a compressor without having to reallocate anything. Same as calling mz_inflateEnd() followed by mz_inflateInit()/mz_inflateInit2(). */
410 MINIZ_EXPORT int mz_inflateReset(mz_streamp pStream);
411
412 /* 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. */
413 /* Parameters: */
414 /* 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. */
415 /* flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH. */
416 /* 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). */
417 /* 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. */
418 /* Return values: */
419 /* 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. */
420 /* 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. */
421 /* MZ_STREAM_ERROR if the stream is bogus. */
422 /* MZ_DATA_ERROR if the deflate stream is invalid. */
423 /* MZ_PARAM_ERROR if one of the parameters is invalid. */
424 /* 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 */
425 /* with more input data, or with more room in the output buffer (except when using single call decompression, described above). */
426 MINIZ_EXPORT int mz_inflate(mz_streamp pStream, int flush);
427
428 /* Deinitializes a decompressor. */
429 MINIZ_EXPORT int mz_inflateEnd(mz_streamp pStream);
430
431 /* Single-call decompression. */
432 /* Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. */
433 MINIZ_EXPORT int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
434 MINIZ_EXPORT int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len);
435#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
436
437 /* Returns a string description of the specified error code, or NULL if the error code is invalid. */
438 MINIZ_EXPORT const char *mz_error(int err);
439
440/* 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. */
441/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project. */
442#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
443 typedef unsigned char Byte;
444 typedef unsigned int uInt;
446 typedef Byte Bytef;
447 typedef uInt uIntf;
448 typedef char charf;
449 typedef int intf;
450 typedef void *voidpf;
451 typedef uLong uLongf;
452 typedef void *voidp;
453 typedef void *const voidpc;
454#define Z_NULL 0
455#define Z_NO_FLUSH MZ_NO_FLUSH
456#define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
457#define Z_SYNC_FLUSH MZ_SYNC_FLUSH
458#define Z_FULL_FLUSH MZ_FULL_FLUSH
459#define Z_FINISH MZ_FINISH
460#define Z_BLOCK MZ_BLOCK
461#define Z_OK MZ_OK
462#define Z_STREAM_END MZ_STREAM_END
463#define Z_NEED_DICT MZ_NEED_DICT
464#define Z_ERRNO MZ_ERRNO
465#define Z_STREAM_ERROR MZ_STREAM_ERROR
466#define Z_DATA_ERROR MZ_DATA_ERROR
467#define Z_MEM_ERROR MZ_MEM_ERROR
468#define Z_BUF_ERROR MZ_BUF_ERROR
469#define Z_VERSION_ERROR MZ_VERSION_ERROR
470#define Z_PARAM_ERROR MZ_PARAM_ERROR
471#define Z_NO_COMPRESSION MZ_NO_COMPRESSION
472#define Z_BEST_SPEED MZ_BEST_SPEED
473#define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION
474#define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
475#define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY
476#define Z_FILTERED MZ_FILTERED
477#define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY
478#define Z_RLE MZ_RLE
479#define Z_FIXED MZ_FIXED
480#define Z_DEFLATED MZ_DEFLATED
481#define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
482 /* See mz_alloc_func */
483 typedef void *(*alloc_func)(void *opaque, size_t items, size_t size);
484 /* See mz_free_func */
485 typedef void (*free_func)(void *opaque, void *address);
486
487#define internal_state mz_internal_state
488#define z_stream mz_stream
489
490#ifndef MINIZ_NO_DEFLATE_APIS
491 /* Compatiblity with zlib API. See called functions for documentation */
492 static int deflateInit(mz_streamp pStream, int level)
493 {
494 return mz_deflateInit(pStream, level);
495 }
496 static int deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy)
497 {
498 return mz_deflateInit2(pStream, level, method, window_bits, mem_level, strategy);
499 }
500 static int deflateReset(mz_streamp pStream)
501 {
502 return mz_deflateReset(pStream);
503 }
504 static int deflate(mz_streamp pStream, int flush)
505 {
506 return mz_deflate(pStream, flush);
507 }
508 static int deflateEnd(mz_streamp pStream)
509 {
510 return mz_deflateEnd(pStream);
511 }
512 static mz_ulong deflateBound(mz_streamp pStream, mz_ulong source_len)
513 {
514 return mz_deflateBound(pStream, source_len);
515 }
516 static int compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
517 {
518 return mz_compress(pDest, pDest_len, pSource, source_len);
519 }
520 static int compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level)
521 {
522 return mz_compress2(pDest, pDest_len, pSource, source_len, level);
523 }
524 static mz_ulong compressBound(mz_ulong source_len)
525 {
526 return mz_compressBound(source_len);
527 }
528#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
529
530#ifndef MINIZ_NO_INFLATE_APIS
531 /* Compatiblity with zlib API. See called functions for documentation */
532 static int inflateInit(mz_streamp pStream)
533 {
534 return mz_inflateInit(pStream);
535 }
536
537 static int inflateInit2(mz_streamp pStream, int window_bits)
538 {
539 return mz_inflateInit2(pStream, window_bits);
540 }
541
542 static int inflateReset(mz_streamp pStream)
543 {
544 return mz_inflateReset(pStream);
545 }
546
547 static int inflate(mz_streamp pStream, int flush)
548 {
549 return mz_inflate(pStream, flush);
550 }
551
552 static int inflateEnd(mz_streamp pStream)
553 {
554 return mz_inflateEnd(pStream);
555 }
556
557 static int uncompress(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong source_len)
558 {
559 return mz_uncompress(pDest, pDest_len, pSource, source_len);
560 }
561
562 static int uncompress2(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong* pSource_len)
563 {
564 return mz_uncompress2(pDest, pDest_len, pSource, pSource_len);
565 }
566#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
567
568 static mz_ulong crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len)
569 {
570 return mz_crc32(crc, ptr, buf_len);
571 }
572
573 static mz_ulong adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
574 {
575 return mz_adler32(adler, ptr, buf_len);
576 }
577
578#define MAX_WBITS 15
579#define MAX_MEM_LEVEL 9
580
581 static const char* zError(int err)
582 {
583 return mz_error(err);
584 }
585#define ZLIB_VERSION MZ_VERSION
586#define ZLIB_VERNUM MZ_VERNUM
587#define ZLIB_VER_MAJOR MZ_VER_MAJOR
588#define ZLIB_VER_MINOR MZ_VER_MINOR
589#define ZLIB_VER_REVISION MZ_VER_REVISION
590#define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
591
592#define zlibVersion mz_version
593#define zlib_version mz_version()
594#endif /* #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES */
595
596#endif /* MINIZ_NO_ZLIB_APIS */
597
598#ifdef __cplusplus
599}
600#endif
601
602#include "miniz_common.h"
603#include "miniz_tdef.h"
604#include "miniz_tinfl.h"
605#include "miniz_zip.h"
MINIZ_EXPORT int mz_inflateInit(mz_streamp pStream)
unsigned long mz_ulong
Definition miniz.h:233
MINIZ_EXPORT mz_ulong mz_compressBound(mz_ulong source_len)
void *(* mz_alloc_func)(void *opaque, size_t items, size_t size)
Definition miniz.h:261
MINIZ_EXPORT int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
struct mz_stream_s mz_stream
MINIZ_EXPORT int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy)
MINIZ_EXPORT int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
MINIZ_EXPORT int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level)
MINIZ_EXPORT int mz_deflateEnd(mz_streamp pStream)
MINIZ_EXPORT const char * mz_error(int err)
MINIZ_EXPORT int mz_inflateEnd(mz_streamp pStream)
@ MZ_BEST_SPEED
Definition miniz.h:269
@ MZ_NO_COMPRESSION
Definition miniz.h:268
@ MZ_UBER_COMPRESSION
Definition miniz.h:271
@ MZ_DEFAULT_LEVEL
Definition miniz.h:272
@ MZ_BEST_COMPRESSION
Definition miniz.h:270
@ MZ_DEFAULT_COMPRESSION
Definition miniz.h:273
MINIZ_EXPORT mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
@ MZ_SYNC_FLUSH
Definition miniz.h:290
@ MZ_BLOCK
Definition miniz.h:293
@ MZ_FULL_FLUSH
Definition miniz.h:291
@ MZ_FINISH
Definition miniz.h:292
@ MZ_PARTIAL_FLUSH
Definition miniz.h:289
@ MZ_NO_FLUSH
Definition miniz.h:288
MINIZ_EXPORT mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len)
mz_ulong uLong
Definition miniz.h:445
MINIZ_EXPORT int mz_deflateInit(mz_streamp pStream, int level)
@ MZ_FILTERED
Definition miniz.h:250
@ MZ_FIXED
Definition miniz.h:253
@ MZ_DEFAULT_STRATEGY
Definition miniz.h:249
@ MZ_RLE
Definition miniz.h:252
@ MZ_HUFFMAN_ONLY
Definition miniz.h:251
int intf
Definition miniz.h:449
uInt uIntf
Definition miniz.h:447
char charf
Definition miniz.h:448
unsigned int uInt
Definition miniz.h:444
MINIZ_EXPORT int mz_inflate(mz_streamp pStream, int flush)
MINIZ_EXPORT mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len)
MINIZ_EXPORT void mz_free(void *p)
MINIZ_EXPORT int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len)
@ MZ_MEM_ERROR
Definition miniz.h:305
@ MZ_PARAM_ERROR
Definition miniz.h:308
@ MZ_NEED_DICT
Definition miniz.h:301
@ MZ_VERSION_ERROR
Definition miniz.h:307
@ MZ_STREAM_END
Definition miniz.h:300
@ MZ_ERRNO
Definition miniz.h:302
@ MZ_OK
Definition miniz.h:299
@ MZ_BUF_ERROR
Definition miniz.h:306
@ MZ_STREAM_ERROR
Definition miniz.h:303
@ MZ_DATA_ERROR
Definition miniz.h:304
MINIZ_EXPORT int mz_deflate(mz_streamp pStream, int flush)
void(* mz_free_func)(void *opaque, void *address)
Definition miniz.h:262
Byte Bytef
Definition miniz.h:446
void * voidpf
Definition miniz.h:450
MINIZ_EXPORT const char * mz_version(void)
uLong uLongf
Definition miniz.h:451
MINIZ_EXPORT int mz_inflateReset(mz_streamp pStream)
void(* free_func)(void *opaque, void *address)
Definition miniz.h:485
MINIZ_EXPORT int mz_inflateInit2(mz_streamp pStream, int window_bits)
unsigned char Byte
Definition miniz.h:443
mz_stream * mz_streamp
Definition miniz.h:339
MINIZ_EXPORT int mz_deflateReset(mz_streamp pStream)
void * voidp
Definition miniz.h:452
void *const voidpc
Definition miniz.h:453
Definition miniz.h:318
mz_ulong adler
Definition miniz.h:335
unsigned char * next_out
Definition miniz.h:323
void * opaque
Definition miniz.h:332
int data_type
Definition miniz.h:334
mz_free_func zfree
Definition miniz.h:331
mz_ulong total_out
Definition miniz.h:325
unsigned int avail_out
Definition miniz.h:324
struct mz_internal_state * state
Definition miniz.h:328
const unsigned char * next_in
Definition miniz.h:319
unsigned int avail_in
Definition miniz.h:320
mz_alloc_func zalloc
Definition miniz.h:330
mz_ulong total_in
Definition miniz.h:321
char * msg
Definition miniz.h:327
mz_ulong reserved
Definition miniz.h:336