Oolite
Loading...
Searching...
No Matches
miniz.h
Go to the documentation of this file.
1#ifndef MINIZ_EXPORT
2#define MINIZ_EXPORT
3#endif
4/* miniz.c 3.0.0 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
5 See "unlicense" statement at the end of this file.
6 Rich Geldreich <richgel99@gmail.com>, last updated Oct. 13, 2013
7 Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
8
9 Most API's defined in miniz.c are optional. For example, to disable the archive related functions just define
10 MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros).
11
12 * Low-level Deflate/Inflate implementation notes:
13
14 Compression: Use the "tdefl" API's. The compressor supports raw, static, and dynamic blocks, lazy or
15 greedy parsing, match length filtering, RLE-only, and Huffman-only streams. It performs and compresses
16 approximately as well as zlib.
17
18 Decompression: Use the "tinfl" API's. The entire decompressor is implemented as a single function
19 coroutine: see tinfl_decompress(). It supports decompression into a 32KB (or larger power of 2) wrapping buffer, or into a memory
20 block large enough to hold the entire file.
21
22 The low-level tdefl/tinfl API's do not make any use of dynamic memory allocation.
23
24 * zlib-style API notes:
25
26 miniz.c implements a fairly large subset of zlib. There's enough functionality present for it to be a drop-in
27 zlib replacement in many apps:
28 The z_stream struct, optional memory allocation callbacks
29 deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound
30 inflateInit/inflateInit2/inflate/inflateReset/inflateEnd
31 compress, compress2, compressBound, uncompress
32 CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines.
33 Supports raw deflate streams or standard zlib streams with adler-32 checking.
34
35 Limitations:
36 The callback API's are not implemented yet. No support for gzip headers or zlib static dictionaries.
37 I've tried to closely emulate zlib's various flavors of stream flushing and return status codes, but
38 there are no guarantees that miniz.c pulls this off perfectly.
39
40 * PNG writing: See the tdefl_write_image_to_png_file_in_memory() function, originally written by
41 Alex Evans. Supports 1-4 bytes/pixel images.
42
43 * ZIP archive API notes:
44
45 The ZIP archive API's where designed with simplicity and efficiency in mind, with just enough abstraction to
46 get the job done with minimal fuss. There are simple API's to retrieve file information, read files from
47 existing archives, create new archives, append new files to existing archives, or clone archive data from
48 one archive to another. It supports archives located in memory or the heap, on disk (using stdio.h),
49 or you can specify custom file read/write callbacks.
50
51 - Archive reading: Just call this function to read a single file from a disk archive:
52
53 void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name,
54 size_t *pSize, mz_uint zip_flags);
55
56 For more complex cases, use the "mz_zip_reader" functions. Upon opening an archive, the entire central
57 directory is located and read as-is into memory, and subsequent file access only occurs when reading individual files.
58
59 - Archives file scanning: The simple way is to use this function to scan a loaded archive for a specific file:
60
61 int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
62
63 The locate operation can optionally check file comments too, which (as one example) can be used to identify
64 multiple versions of the same file in an archive. This function uses a simple linear search through the central
65 directory, so it's not very fast.
66
67 Alternately, you can iterate through all the files in an archive (using mz_zip_reader_get_num_files()) and
68 retrieve detailed info on each file by calling mz_zip_reader_file_stat().
69
70 - Archive creation: Use the "mz_zip_writer" functions. The ZIP writer immediately writes compressed file data
71 to disk and builds an exact image of the central directory in memory. The central directory image is written
72 all at once at the end of the archive file when the archive is finalized.
73
74 The archive writer can optionally align each file's local header and file data to any power of 2 alignment,
75 which can be useful when the archive will be read from optical media. Also, the writer supports placing
76 arbitrary data blobs at the very beginning of ZIP archives. Archives written using either feature are still
77 readable by any ZIP tool.
78
79 - Archive appending: The simple way to add a single file to an archive is to call this function:
80
81 mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name,
82 const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
83
84 The archive will be created if it doesn't already exist, otherwise it'll be appended to.
85 Note the appending is done in-place and is not an atomic operation, so if something goes wrong
86 during the operation it's possible the archive could be left without a central directory (although the local
87 file headers and file data will be fine, so the archive will be recoverable).
88
89 For more complex archive modification scenarios:
90 1. The safest way is to use a mz_zip_reader to read the existing archive, cloning only those bits you want to
91 preserve into a new archive using using the mz_zip_writer_add_from_zip_reader() function (which compiles the
92 compressed file data as-is). When you're done, delete the old archive and rename the newly written archive, and
93 you're done. This is safe but requires a bunch of temporary disk space or heap memory.
94
95 2. Or, you can convert an mz_zip_reader in-place to an mz_zip_writer using mz_zip_writer_init_from_reader(),
96 append new files as needed, then finalize the archive which will write an updated central directory to the
97 original archive. (This is basically what mz_zip_add_mem_to_archive_file_in_place() does.) There's a
98 possibility that the archive's central directory could be lost with this method if anything goes wrong, though.
99
100 - ZIP archive support limitations:
101 No spanning support. Extraction functions can only handle unencrypted, stored or deflated files.
102 Requires streams capable of seeking.
103
104 * This is a header file library, like stb_image.c. To get only a header file, either cut and paste the
105 below header, or create miniz.h, #define MINIZ_HEADER_FILE_ONLY, and then include miniz.c from it.
106
107 * Important: For best perf. be sure to customize the below macros for your target platform:
108 #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
109 #define MINIZ_LITTLE_ENDIAN 1
110 #define MINIZ_HAS_64BIT_REGISTERS 1
111
112 * On platforms using glibc, Be sure to "#define _LARGEFILE64_SOURCE 1" before including miniz.c to ensure miniz
113 uses the 64-bit variants: fopen64(), stat64(), etc. Otherwise you won't be able to process large files
114 (i.e. 32-bit stat() fails for me on files > 0x7FFFFFFF bytes).
115*/
116#pragma once
117
118/* Defines to completely disable specific portions of miniz.c:
119 If all macros here are defined the only functionality remaining will be CRC-32 and adler-32. */
120
121/* Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O. */
122/*#define MINIZ_NO_STDIO */
123
124/* If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or */
125/* get/set file times, and the C run-time funcs that get/set times won't be called. */
126/* The current downside is the times written to your archives will be from 1979. */
127/*#define MINIZ_NO_TIME */
128
129/* Define MINIZ_NO_DEFLATE_APIS to disable all compression API's. */
130/*#define MINIZ_NO_DEFLATE_APIS */
131
132/* Define MINIZ_NO_INFLATE_APIS to disable all decompression API's. */
133/*#define MINIZ_NO_INFLATE_APIS */
134
135/* Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. */
136/*#define MINIZ_NO_ARCHIVE_APIS */
137
138/* Define MINIZ_NO_ARCHIVE_WRITING_APIS to disable all writing related ZIP archive API's. */
139/*#define MINIZ_NO_ARCHIVE_WRITING_APIS */
140
141/* Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's. */
142/*#define MINIZ_NO_ZLIB_APIS */
143
144/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib. */
145/*#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES */
146
147/* Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
148 Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
149 callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
150 functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. */
151/*#define MINIZ_NO_MALLOC */
152
153#ifdef MINIZ_NO_INFLATE_APIS
154#define MINIZ_NO_ARCHIVE_APIS
155#endif
156
157#ifdef MINIZ_NO_DEFLATE_APIS
158#define MINIZ_NO_ARCHIVE_WRITING_APIS
159#endif
160
161#if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
162/* TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux */
163#define MINIZ_NO_TIME
164#endif
165
166#include <stddef.h>
167
168#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
169#include <time.h>
170#endif
171
172#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
173/* MINIZ_X86_OR_X64_CPU is only used to help set the below macros. */
174#define MINIZ_X86_OR_X64_CPU 1
175#else
176#define MINIZ_X86_OR_X64_CPU 0
177#endif
178
179/* Set MINIZ_LITTLE_ENDIAN only if not set */
180#if !defined(MINIZ_LITTLE_ENDIAN)
181#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
182
183#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
184/* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */
185#define MINIZ_LITTLE_ENDIAN 1
186#else
187#define MINIZ_LITTLE_ENDIAN 0
188#endif
189
190#else
191
192#if MINIZ_X86_OR_X64_CPU
193#define MINIZ_LITTLE_ENDIAN 1
194#else
195#define MINIZ_LITTLE_ENDIAN 0
196#endif
197
198#endif
199#endif
200
201/* Using unaligned loads and stores causes errors when using UBSan */
202#if defined(__has_feature)
203#if __has_feature(undefined_behavior_sanitizer)
204#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
205#endif
206#endif
207
208/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES only if not set */
209#if !defined(MINIZ_USE_UNALIGNED_LOADS_AND_STORES)
210#if MINIZ_X86_OR_X64_CPU
211/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses. */
212#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
213#define MINIZ_UNALIGNED_USE_MEMCPY
214#else
215#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
216#endif
217#endif
218
219#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
220/* 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). */
221#define MINIZ_HAS_64BIT_REGISTERS 1
222#else
223#define MINIZ_HAS_64BIT_REGISTERS 0
224#endif
225
226#ifdef __cplusplus
227extern "C" {
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! */
233typedef 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. */
236MINIZ_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. */
240MINIZ_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. */
244MINIZ_EXPORT mz_ulong mz_crc32(mz_ulong crc, const unsigned char* ptr, size_t buf_len);
245
246/* Compression strategies. */
247enum {
253};
254
255/* Method */
256#define MZ_DEFLATED 8
257
258/* Heap allocation callbacks.
259Note that mz_alloc_func parameter types purposely differ from zlib's: items/size is size_t, not unsigned long. */
260typedef void* (*mz_alloc_func)(void* opaque, size_t items, size_t size);
261typedef void (*mz_free_func)(void* opaque, void* address);
262typedef void* (*mz_realloc_func)(void* opaque, void* address, size_t items, size_t size);
263
264/* 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. */
265enum {
272};
273
274#define MZ_VERSION "11.0.2"
275#define MZ_VERNUM 0xB002
276#define MZ_VER_MAJOR 11
277#define MZ_VER_MINOR 2
278#define MZ_VER_REVISION 0
279#define MZ_VER_SUBREVISION 0
280
281#ifndef MINIZ_NO_ZLIB_APIS
282
283/* 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). */
284enum {
291};
292
293/* Return status codes. MZ_PARAM_ERROR is non-standard. */
294enum {
295 MZ_OK = 0,
305};
306
307/* Window bits */
308#define MZ_DEFAULT_WINDOW_BITS 15
309
310struct mz_internal_state;
311
312/* Compression/decompression stream struct. */
313typedef struct mz_stream_s {
314 const unsigned char* next_in; /* pointer to next byte to read */
315 unsigned int avail_in; /* number of bytes available at next_in */
316 mz_ulong total_in; /* total number of bytes consumed so far */
317
318 unsigned char* next_out; /* pointer to next byte to write */
319 unsigned int avail_out; /* number of bytes that can be written to next_out */
320 mz_ulong total_out; /* total number of bytes produced so far */
321
322 char* msg; /* error msg (unused) */
323 struct mz_internal_state* state; /* internal state, allocated by zalloc/zfree */
324
325 mz_alloc_func zalloc; /* optional heap allocation function (defaults to malloc) */
326 mz_free_func zfree; /* optional heap free function (defaults to free) */
327 void* opaque; /* heap alloc function user pointer */
328
329 int data_type; /* data_type (unused) */
330 mz_ulong adler; /* adler32 of the source or uncompressed data */
331 mz_ulong reserved; /* not used */
333
335
336/* Returns the version string of miniz.c. */
337MINIZ_EXPORT const char* mz_version(void);
338
339#ifndef MINIZ_NO_DEFLATE_APIS
340
341/* mz_deflateInit() initializes a compressor with default options: */
342/* Parameters: */
343/* pStream must point to an initialized mz_stream struct. */
344/* level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION]. */
345/* level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio. */
346/* (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.) */
347/* Return values: */
348/* MZ_OK on success. */
349/* MZ_STREAM_ERROR if the stream is bogus. */
350/* MZ_PARAM_ERROR if the input parameters are bogus. */
351/* MZ_MEM_ERROR on out of memory. */
352MINIZ_EXPORT int mz_deflateInit(mz_streamp pStream, int level);
353
354/* mz_deflateInit2() is like mz_deflate(), except with more control: */
355/* Additional parameters: */
356/* method must be MZ_DEFLATED */
357/* 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) */
358/* mem_level must be between [1, 9] (it's checked but ignored by miniz.c) */
359MINIZ_EXPORT int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
360
361/* Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2(). */
362MINIZ_EXPORT int mz_deflateReset(mz_streamp pStream);
363
364/* mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible. */
365/* Parameters: */
366/* 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. */
367/* flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH. */
368/* Return values: */
369/* 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). */
370/* 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. */
371/* MZ_STREAM_ERROR if the stream is bogus. */
372/* MZ_PARAM_ERROR if one of the parameters is invalid. */
373/* 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.) */
374MINIZ_EXPORT int mz_deflate(mz_streamp pStream, int flush);
375
376/* mz_deflateEnd() deinitializes a compressor: */
377/* Return values: */
378/* MZ_OK on success. */
379/* MZ_STREAM_ERROR if the stream is bogus. */
380MINIZ_EXPORT int mz_deflateEnd(mz_streamp pStream);
381
382/* 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. */
383MINIZ_EXPORT mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
384
385/* Single-call compression functions mz_compress() and mz_compress2(): */
386/* Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure. */
387MINIZ_EXPORT int mz_compress(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong source_len);
388MINIZ_EXPORT int mz_compress2(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong source_len, int level);
389
390/* mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress(). */
391MINIZ_EXPORT mz_ulong mz_compressBound(mz_ulong source_len);
392
393#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
394
395#ifndef MINIZ_NO_INFLATE_APIS
396
397/* Initializes a decompressor. */
398MINIZ_EXPORT int mz_inflateInit(mz_streamp pStream);
399
400/* 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: */
401/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). */
402MINIZ_EXPORT int mz_inflateInit2(mz_streamp pStream, int window_bits);
403
404/* Quickly resets a compressor without having to reallocate anything. Same as calling mz_inflateEnd() followed by mz_inflateInit()/mz_inflateInit2(). */
405MINIZ_EXPORT int mz_inflateReset(mz_streamp pStream);
406
407/* 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. */
408/* Parameters: */
409/* 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. */
410/* flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH. */
411/* 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). */
412/* 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. */
413/* Return values: */
414/* 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. */
415/* 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. */
416/* MZ_STREAM_ERROR if the stream is bogus. */
417/* MZ_DATA_ERROR if the deflate stream is invalid. */
418/* MZ_PARAM_ERROR if one of the parameters is invalid. */
419/* 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 */
420/* with more input data, or with more room in the output buffer (except when using single call decompression, described above). */
421MINIZ_EXPORT int mz_inflate(mz_streamp pStream, int flush);
422
423/* Deinitializes a decompressor. */
424MINIZ_EXPORT int mz_inflateEnd(mz_streamp pStream);
425
426/* Single-call decompression. */
427/* Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. */
428MINIZ_EXPORT int mz_uncompress(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong source_len);
429MINIZ_EXPORT int mz_uncompress2(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong* pSource_len);
430#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
431
432/* Returns a string description of the specified error code, or NULL if the error code is invalid. */
433MINIZ_EXPORT const char* mz_error(int err);
434
435/* 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. */
436/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project. */
437#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
438typedef unsigned char Byte;
439typedef unsigned int uInt;
441typedef Byte Bytef;
442typedef uInt uIntf;
443typedef char charf;
444typedef int intf;
445typedef void* voidpf;
446typedef uLong uLongf;
447typedef void* voidp;
448typedef void* const voidpc;
449#define Z_NULL 0
450#define Z_NO_FLUSH MZ_NO_FLUSH
451#define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
452#define Z_SYNC_FLUSH MZ_SYNC_FLUSH
453#define Z_FULL_FLUSH MZ_FULL_FLUSH
454#define Z_FINISH MZ_FINISH
455#define Z_BLOCK MZ_BLOCK
456#define Z_OK MZ_OK
457#define Z_STREAM_END MZ_STREAM_END
458#define Z_NEED_DICT MZ_NEED_DICT
459#define Z_ERRNO MZ_ERRNO
460#define Z_STREAM_ERROR MZ_STREAM_ERROR
461#define Z_DATA_ERROR MZ_DATA_ERROR
462#define Z_MEM_ERROR MZ_MEM_ERROR
463#define Z_BUF_ERROR MZ_BUF_ERROR
464#define Z_VERSION_ERROR MZ_VERSION_ERROR
465#define Z_PARAM_ERROR MZ_PARAM_ERROR
466#define Z_NO_COMPRESSION MZ_NO_COMPRESSION
467#define Z_BEST_SPEED MZ_BEST_SPEED
468#define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION
469#define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
470#define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY
471#define Z_FILTERED MZ_FILTERED
472#define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY
473#define Z_RLE MZ_RLE
474#define Z_FIXED MZ_FIXED
475#define Z_DEFLATED MZ_DEFLATED
476#define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
477#define alloc_func mz_alloc_func
478#define free_func mz_free_func
479#define internal_state mz_internal_state
480#define z_stream mz_stream
481
482#ifndef MINIZ_NO_DEFLATE_APIS
483#define deflateInit mz_deflateInit
484#define deflateInit2 mz_deflateInit2
485#define deflateReset mz_deflateReset
486#define deflate mz_deflate
487#define deflateEnd mz_deflateEnd
488#define deflateBound mz_deflateBound
489#define compress mz_compress
490#define compress2 mz_compress2
491#define compressBound mz_compressBound
492#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
493
494#ifndef MINIZ_NO_INFLATE_APIS
495#define inflateInit mz_inflateInit
496#define inflateInit2 mz_inflateInit2
497#define inflateReset mz_inflateReset
498#define inflate mz_inflate
499#define inflateEnd mz_inflateEnd
500#define uncompress mz_uncompress
501#define uncompress2 mz_uncompress2
502#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
503
504#define crc32 mz_crc32
505#define adler32 mz_adler32
506#define MAX_WBITS 15
507#define MAX_MEM_LEVEL 9
508#define zError mz_error
509#define ZLIB_VERSION MZ_VERSION
510#define ZLIB_VERNUM MZ_VERNUM
511#define ZLIB_VER_MAJOR MZ_VER_MAJOR
512#define ZLIB_VER_MINOR MZ_VER_MINOR
513#define ZLIB_VER_REVISION MZ_VER_REVISION
514#define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
515#define zlibVersion mz_version
516#define zlib_version mz_version()
517#endif /* #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES */
518
519#endif /* MINIZ_NO_ZLIB_APIS */
520
521#ifdef __cplusplus
522}
523#endif
524
525#pragma once
526#include <assert.h>
527#include <stdint.h>
528#include <stdlib.h>
529#include <string.h>
530
531/* ------------------- Types and macros */
532typedef unsigned char mz_uint8;
533typedef signed short mz_int16;
534typedef unsigned short mz_uint16;
535typedef unsigned int mz_uint32;
536typedef unsigned int mz_uint;
537typedef int64_t mz_int64;
538typedef uint64_t mz_uint64;
539typedef int mz_bool;
540
541#define MZ_FALSE (0)
542#define MZ_TRUE (1)
543
544/* Works around MSVC's spammy "warning C4127: conditional expression is constant" message. */
545#ifdef _MSC_VER
546#define MZ_MACRO_END while (0, 0)
547#else
548#define MZ_MACRO_END while (0)
549#endif
550
551#ifdef MINIZ_NO_STDIO
552#define MZ_FILE void*
553#else
554#include <stdio.h>
555#define MZ_FILE FILE
556#endif /* #ifdef MINIZ_NO_STDIO */
557
558#ifdef MINIZ_NO_TIME
559typedef struct mz_dummy_time_t_tag {
560 mz_uint32 m_dummy1;
561 mz_uint32 m_dummy2;
562} mz_dummy_time_t;
563#define MZ_TIME_T mz_dummy_time_t
564#else
565#define MZ_TIME_T time_t
566#endif
567
568#define MZ_ASSERT(x) assert(x)
569
570#ifdef MINIZ_NO_MALLOC
571#define MZ_MALLOC(x) NULL
572#define MZ_FREE(x) (void)x, ((void)0)
573#define MZ_REALLOC(p, x) NULL
574#else
575#define MZ_MALLOC(x) malloc(x)
576#define MZ_FREE(x) free(x)
577#define MZ_REALLOC(p, x) realloc(p, x)
578#endif
579
580#define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b))
581#define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b))
582#define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
583#define MZ_CLEAR_ARR(obj) memset((obj), 0, sizeof(obj))
584#define MZ_CLEAR_PTR(obj) memset((obj), 0, sizeof(*obj))
585
586#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
587#define MZ_READ_LE16(p) *((const mz_uint16*)(p))
588#define MZ_READ_LE32(p) *((const mz_uint32*)(p))
589#else
590#define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8*)(p))[0]) | ((mz_uint32)(((const mz_uint8*)(p))[1]) << 8U))
591#define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8*)(p))[0]) | ((mz_uint32)(((const mz_uint8*)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8*)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8*)(p))[3]) << 24U))
592#endif
593
594#define MZ_READ_LE64(p) (((mz_uint64)MZ_READ_LE32(p)) | (((mz_uint64)MZ_READ_LE32((const mz_uint8*)(p) + sizeof(mz_uint32))) << 32U))
595
596#ifdef _MSC_VER
597#define MZ_FORCEINLINE __forceinline
598#elif defined(__GNUC__)
599#define MZ_FORCEINLINE __inline__ __attribute__((__always_inline__))
600#else
601#define MZ_FORCEINLINE inline
602#endif
603
604#ifdef __cplusplus
605extern "C" {
606#endif
607
608extern MINIZ_EXPORT void* miniz_def_alloc_func(void* opaque, size_t items, size_t size);
609extern MINIZ_EXPORT void miniz_def_free_func(void* opaque, void* address);
610extern MINIZ_EXPORT void* miniz_def_realloc_func(void* opaque, void* address, size_t items, size_t size);
611
612#define MZ_UINT16_MAX (0xFFFFU)
613#define MZ_UINT32_MAX (0xFFFFFFFFU)
614
615#ifdef __cplusplus
616}
617#endif
618#pragma once
619
620#ifndef MINIZ_NO_DEFLATE_APIS
621
622#ifdef __cplusplus
623extern "C" {
624#endif
625/* ------------------- Low-level Compression API Definitions */
626
627/* Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently). */
628#define TDEFL_LESS_MEMORY 0
629
630/* tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search): */
631/* 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). */
632enum {
633 TDEFL_HUFFMAN_ONLY = 0,
634 TDEFL_DEFAULT_MAX_PROBES = 128,
635 TDEFL_MAX_PROBES_MASK = 0xFFF
636};
637
638/* 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. */
639/* TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers). */
640/* TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing. */
641/* 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). */
642/* TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1) */
643/* TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled. */
644/* TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables. */
645/* TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks. */
646/* The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK). */
647enum {
648 TDEFL_WRITE_ZLIB_HEADER = 0x01000,
649 TDEFL_COMPUTE_ADLER32 = 0x02000,
650 TDEFL_GREEDY_PARSING_FLAG = 0x04000,
651 TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
652 TDEFL_RLE_MATCHES = 0x10000,
653 TDEFL_FILTER_MATCHES = 0x20000,
654 TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000,
655 TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
656};
657
658/* High level compression functions: */
659/* tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc(). */
660/* On entry: */
661/* pSrc_buf, src_buf_len: Pointer and size of source block to compress. */
662/* flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression. */
663/* On return: */
664/* Function returns a pointer to the compressed data, or NULL on failure. */
665/* *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data. */
666/* The caller must free() the returned block when it's no longer needed. */
667MINIZ_EXPORT void* tdefl_compress_mem_to_heap(const void* pSrc_buf, size_t src_buf_len, size_t* pOut_len, int flags);
668
669/* tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory. */
670/* Returns 0 on failure. */
671MINIZ_EXPORT 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);
672
673/* Compresses an image to a compressed PNG file in memory. */
674/* On entry: */
675/* pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4. */
676/* The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory. */
677/* 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 */
678/* If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps). */
679/* On return: */
680/* Function returns a pointer to the compressed data, or NULL on failure. */
681/* *pLen_out will be set to the size of the PNG image file. */
682/* The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed. */
683MINIZ_EXPORT 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);
684MINIZ_EXPORT void* tdefl_write_image_to_png_file_in_memory(const void* pImage, int w, int h, int num_chans, size_t* pLen_out);
685
686/* Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time. */
687typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void* pUser);
688
689/* tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally. */
690MINIZ_EXPORT 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);
691
692enum {
693 TDEFL_MAX_HUFF_TABLES = 3,
694 TDEFL_MAX_HUFF_SYMBOLS_0 = 288,
695 TDEFL_MAX_HUFF_SYMBOLS_1 = 32,
696 TDEFL_MAX_HUFF_SYMBOLS_2 = 19,
697 TDEFL_LZ_DICT_SIZE = 32768,
698 TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1,
699 TDEFL_MIN_MATCH_LEN = 3,
700 TDEFL_MAX_MATCH_LEN = 258
701};
702
703/* TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes). */
704#if TDEFL_LESS_MEMORY
705enum {
706 TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024,
707 TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10,
708 TDEFL_MAX_HUFF_SYMBOLS = 288,
709 TDEFL_LZ_HASH_BITS = 12,
710 TDEFL_LEVEL1_HASH_SIZE_MASK = 4095,
711 TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3,
712 TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS
713};
714#else
715enum {
716 TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024,
717 TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10,
718 TDEFL_MAX_HUFF_SYMBOLS = 288,
719 TDEFL_LZ_HASH_BITS = 15,
720 TDEFL_LEVEL1_HASH_SIZE_MASK = 4095,
721 TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3,
722 TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS
723};
724#endif
725
726/* 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. */
727typedef enum {
728 TDEFL_STATUS_BAD_PARAM = -2,
729 TDEFL_STATUS_PUT_BUF_FAILED = -1,
730 TDEFL_STATUS_OKAY = 0,
731 TDEFL_STATUS_DONE = 1
732} tdefl_status;
733
734/* Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums */
735typedef enum {
736 TDEFL_NO_FLUSH = 0,
737 TDEFL_SYNC_FLUSH = 2,
738 TDEFL_FULL_FLUSH = 3,
739 TDEFL_FINISH = 4
740} tdefl_flush;
741
742/* tdefl's compression state structure. */
743typedef struct
744{
745 tdefl_put_buf_func_ptr m_pPut_buf_func;
746 void* m_pPut_buf_user;
747 mz_uint m_flags, m_max_probes[2];
748 int m_greedy_parsing;
749 mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size;
750 mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end;
751 mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer;
752 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;
753 tdefl_status m_prev_return_status;
754 const void* m_pIn_buf;
755 void* m_pOut_buf;
756 size_t *m_pIn_buf_size, *m_pOut_buf_size;
757 tdefl_flush m_flush;
758 const mz_uint8* m_pSrc;
759 size_t m_src_buf_left, m_out_buf_ofs;
760 mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1];
761 mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
762 mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
763 mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
764 mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE];
765 mz_uint16 m_next[TDEFL_LZ_DICT_SIZE];
766 mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE];
767 mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
768} tdefl_compressor;
769
770/* Initializes the compressor. */
771/* There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory. */
772/* 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. */
773/* If pBut_buf_func is NULL the user should always call the tdefl_compress() API. */
774/* flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.) */
775MINIZ_EXPORT tdefl_status tdefl_init(tdefl_compressor* d, tdefl_put_buf_func_ptr pPut_buf_func, void* pPut_buf_user, int flags);
776
777/* 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. */
778MINIZ_EXPORT 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);
779
780/* tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr. */
781/* tdefl_compress_buffer() always consumes the entire input buffer. */
782MINIZ_EXPORT tdefl_status tdefl_compress_buffer(tdefl_compressor* d, const void* pIn_buf, size_t in_buf_size, tdefl_flush flush);
783
784MINIZ_EXPORT tdefl_status tdefl_get_prev_return_status(tdefl_compressor* d);
785MINIZ_EXPORT mz_uint32 tdefl_get_adler32(tdefl_compressor* d);
786
787/* Create tdefl_compress() flags given zlib-style compression parameters. */
788/* level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) */
789/* window_bits may be -15 (raw deflate) or 15 (zlib) */
790/* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED */
791MINIZ_EXPORT mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
792
793#ifndef MINIZ_NO_MALLOC
794/* Allocate the tdefl_compressor structure in C so that */
795/* non-C language bindings to tdefl_ API don't need to worry about */
796/* structure size and allocation mechanism. */
797MINIZ_EXPORT tdefl_compressor* tdefl_compressor_alloc(void);
798MINIZ_EXPORT void tdefl_compressor_free(tdefl_compressor* pComp);
799#endif
800
801#ifdef __cplusplus
802}
803#endif
804
805#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
806#pragma once
807
808/* ------------------- Low-level Decompression API Definitions */
809
810#ifndef MINIZ_NO_INFLATE_APIS
811
812#ifdef __cplusplus
813extern "C" {
814#endif
815/* Decompression flags used by tinfl_decompress(). */
816/* 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. */
817/* 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. */
818/* 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). */
819/* TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. */
820enum {
821 TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
822 TINFL_FLAG_HAS_MORE_INPUT = 2,
823 TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
824 TINFL_FLAG_COMPUTE_ADLER32 = 8
825};
826
827/* High level decompression functions: */
828/* tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc(). */
829/* On entry: */
830/* pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress. */
831/* On return: */
832/* Function returns a pointer to the decompressed data, or NULL on failure. */
833/* *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data. */
834/* The caller must call mz_free() on the returned block when it's no longer needed. */
835MINIZ_EXPORT void* tinfl_decompress_mem_to_heap(const void* pSrc_buf, size_t src_buf_len, size_t* pOut_len, int flags);
836
837/* tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory. */
838/* Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success. */
839#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
840MINIZ_EXPORT 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);
841
842/* 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. */
843/* Returns 1 on success or 0 on failure. */
844typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void* pUser);
845MINIZ_EXPORT 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);
846
847struct tinfl_decompressor_tag;
848typedef struct tinfl_decompressor_tag tinfl_decompressor;
849
850#ifndef MINIZ_NO_MALLOC
851/* Allocate the tinfl_decompressor structure in C so that */
852/* non-C language bindings to tinfl_ API don't need to worry about */
853/* structure size and allocation mechanism. */
854MINIZ_EXPORT tinfl_decompressor* tinfl_decompressor_alloc(void);
855MINIZ_EXPORT void tinfl_decompressor_free(tinfl_decompressor* pDecomp);
856#endif
857
858/* Max size of LZ dictionary. */
859#define TINFL_LZ_DICT_SIZE 32768
860
861/* Return status. */
862typedef enum {
863 /* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */
864 /* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */
865 /* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */
866 TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS = -4,
867
868 /* This flag indicates that one or more of the input parameters was obviously bogus. (You can try calling it again, but if you get this error the calling code is wrong.) */
869 TINFL_STATUS_BAD_PARAM = -3,
870
871 /* This flags indicate the inflator is finished but the adler32 check of the uncompressed data didn't match. If you call it again it'll return TINFL_STATUS_DONE. */
872 TINFL_STATUS_ADLER32_MISMATCH = -2,
873
874 /* This flags indicate the inflator has somehow failed (bad code, corrupted input, etc.). If you call it again without resetting via tinfl_init() it it'll just keep on returning the same status failure code. */
875 TINFL_STATUS_FAILED = -1,
876
877 /* Any status code less than TINFL_STATUS_DONE must indicate a failure. */
878
879 /* This flag indicates the inflator has returned every byte of uncompressed data that it can, has consumed every byte that it needed, has successfully reached the end of the deflate stream, and */
880 /* if zlib headers and adler32 checking enabled that it has successfully checked the uncompressed data's adler32. If you call it again you'll just get TINFL_STATUS_DONE over and over again. */
881 TINFL_STATUS_DONE = 0,
882
883 /* This flag indicates the inflator MUST have more input data (even 1 byte) before it can make any more forward progress, or you need to clear the TINFL_FLAG_HAS_MORE_INPUT */
884 /* flag on the next call if you don't have any more source data. If the source data was somehow corrupted it's also possible (but unlikely) for the inflator to keep on demanding input to */
885 /* proceed, so be sure to properly set the TINFL_FLAG_HAS_MORE_INPUT flag. */
886 TINFL_STATUS_NEEDS_MORE_INPUT = 1,
887
888 /* This flag indicates the inflator definitely has 1 or more bytes of uncompressed data available, but it cannot write this data into the output buffer. */
889 /* Note if the source compressed data was corrupted it's possible for the inflator to return a lot of uncompressed data to the caller. I've been assuming you know how much uncompressed data to expect */
890 /* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */
891 /* so I may need to add some code to address this. */
892 TINFL_STATUS_HAS_MORE_OUTPUT = 2
893} tinfl_status;
894
895/* Initializes the decompressor to its initial state. */
896#define tinfl_init(r) \
897 do { \
898 (r)->m_state = 0; \
899 } \
900 MZ_MACRO_END
901#define tinfl_get_adler32(r) (r)->m_check_adler32
902
903/* 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. */
904/* 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. */
905MINIZ_EXPORT 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);
906
907/* Internal/private bits follow. */
908enum {
909 TINFL_MAX_HUFF_TABLES = 3,
910 TINFL_MAX_HUFF_SYMBOLS_0 = 288,
911 TINFL_MAX_HUFF_SYMBOLS_1 = 32,
912 TINFL_MAX_HUFF_SYMBOLS_2 = 19,
913 TINFL_FAST_LOOKUP_BITS = 10,
914 TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
915};
916
917#if MINIZ_HAS_64BIT_REGISTERS
918#define TINFL_USE_64BIT_BITBUF 1
919#else
920#define TINFL_USE_64BIT_BITBUF 0
921#endif
922
923#if TINFL_USE_64BIT_BITBUF
924typedef mz_uint64 tinfl_bit_buf_t;
925#define TINFL_BITBUF_SIZE (64)
926#else
927typedef mz_uint32 tinfl_bit_buf_t;
928#define TINFL_BITBUF_SIZE (32)
929#endif
930
931struct tinfl_decompressor_tag {
932 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];
933 tinfl_bit_buf_t m_bit_buf;
934 size_t m_dist_from_out_buf_start;
935 mz_int16 m_look_up[TINFL_MAX_HUFF_TABLES][TINFL_FAST_LOOKUP_SIZE];
936 mz_int16 m_tree_0[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
937 mz_int16 m_tree_1[TINFL_MAX_HUFF_SYMBOLS_1 * 2];
938 mz_int16 m_tree_2[TINFL_MAX_HUFF_SYMBOLS_2 * 2];
939 mz_uint8 m_code_size_0[TINFL_MAX_HUFF_SYMBOLS_0];
940 mz_uint8 m_code_size_1[TINFL_MAX_HUFF_SYMBOLS_1];
941 mz_uint8 m_code_size_2[TINFL_MAX_HUFF_SYMBOLS_2];
942 mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
943};
944
945#ifdef __cplusplus
946}
947#endif
948
949#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
950
951#pragma once
952
953/* ------------------- ZIP archive reading/writing */
954
955#ifndef MINIZ_NO_ARCHIVE_APIS
956
957#ifdef __cplusplus
958extern "C" {
959#endif
960
961enum {
962 /* Note: These enums can be reduced as needed to save memory or stack space - they are pretty conservative. */
963 MZ_ZIP_MAX_IO_BUF_SIZE = 64 * 1024,
964 MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 512,
965 MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 512
966};
967
968typedef struct
969{
970 /* Central directory file index. */
971 mz_uint32 m_file_index;
972
973 /* Byte offset of this entry in the archive's central directory. Note we currently only support up to UINT_MAX or less bytes in the central dir. */
974 mz_uint64 m_central_dir_ofs;
975
976 /* These fields are copied directly from the zip's central dir. */
977 mz_uint16 m_version_made_by;
978 mz_uint16 m_version_needed;
979 mz_uint16 m_bit_flag;
980 mz_uint16 m_method;
981
982 /* CRC-32 of uncompressed data. */
983 mz_uint32 m_crc32;
984
985 /* File's compressed size. */
986 mz_uint64 m_comp_size;
987
988 /* File's uncompressed size. Note, I've seen some old archives where directory entries had 512 bytes for their uncompressed sizes, but when you try to unpack them you actually get 0 bytes. */
989 mz_uint64 m_uncomp_size;
990
991 /* Zip internal and external file attributes. */
992 mz_uint16 m_internal_attr;
993 mz_uint32 m_external_attr;
994
995 /* Entry's local header file offset in bytes. */
996 mz_uint64 m_local_header_ofs;
997
998 /* Size of comment in bytes. */
999 mz_uint32 m_comment_size;
1000
1001 /* MZ_TRUE if the entry appears to be a directory. */
1002 mz_bool m_is_directory;
1003
1004 /* MZ_TRUE if the entry uses encryption/strong encryption (which miniz_zip doesn't support) */
1005 mz_bool m_is_encrypted;
1006
1007 /* MZ_TRUE if the file is not encrypted, a patch file, and if it uses a compression method we support. */
1008 mz_bool m_is_supported;
1009
1010 /* Filename. If string ends in '/' it's a subdirectory entry. */
1011 /* Guaranteed to be zero terminated, may be truncated to fit. */
1012 char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
1013
1014 /* Comment field. */
1015 /* Guaranteed to be zero terminated, may be truncated to fit. */
1016 char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
1017
1018#ifdef MINIZ_NO_TIME
1019 MZ_TIME_T m_padding;
1020#else
1021 MZ_TIME_T m_time;
1022#endif
1023} mz_zip_archive_file_stat;
1024
1025typedef size_t (*mz_file_read_func)(void* pOpaque, mz_uint64 file_ofs, void* pBuf, size_t n);
1026typedef size_t (*mz_file_write_func)(void* pOpaque, mz_uint64 file_ofs, const void* pBuf, size_t n);
1027typedef mz_bool (*mz_file_needs_keepalive)(void* pOpaque);
1028
1030typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
1031
1032typedef enum {
1033 MZ_ZIP_MODE_INVALID = 0,
1034 MZ_ZIP_MODE_READING = 1,
1035 MZ_ZIP_MODE_WRITING = 2,
1036 MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
1037} mz_zip_mode;
1038
1039typedef enum {
1040 MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
1041 MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
1042 MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
1043 MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800,
1044 MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG = 0x1000, /* if enabled, mz_zip_reader_locate_file() will be called on each file as its validated to ensure the func finds the file in the central dir (intended for testing) */
1045 MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000, /* validate the local headers, but don't decompress the entire file and check the crc32 */
1046 MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000, /* always use the zip64 file format, instead of the original zip file format with automatic switch to zip64. Use as flags parameter with mz_zip_writer_init*_v2 */
1047 MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000,
1048 MZ_ZIP_FLAG_ASCII_FILENAME = 0x10000,
1049 /*After adding a compressed file, seek back
1050 to local file header and set the correct sizes*/
1051 MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE = 0x20000
1052} mz_zip_flags;
1053
1054typedef enum {
1055 MZ_ZIP_TYPE_INVALID = 0,
1056 MZ_ZIP_TYPE_USER,
1057 MZ_ZIP_TYPE_MEMORY,
1058 MZ_ZIP_TYPE_HEAP,
1059 MZ_ZIP_TYPE_FILE,
1060 MZ_ZIP_TYPE_CFILE,
1061 MZ_ZIP_TOTAL_TYPES
1062} mz_zip_type;
1063
1064/* miniz error codes. Be sure to update mz_zip_get_error_string() if you add or modify this enum. */
1065typedef enum {
1066 MZ_ZIP_NO_ERROR = 0,
1067 MZ_ZIP_UNDEFINED_ERROR,
1068 MZ_ZIP_TOO_MANY_FILES,
1069 MZ_ZIP_FILE_TOO_LARGE,
1070 MZ_ZIP_UNSUPPORTED_METHOD,
1071 MZ_ZIP_UNSUPPORTED_ENCRYPTION,
1072 MZ_ZIP_UNSUPPORTED_FEATURE,
1073 MZ_ZIP_FAILED_FINDING_CENTRAL_DIR,
1074 MZ_ZIP_NOT_AN_ARCHIVE,
1075 MZ_ZIP_INVALID_HEADER_OR_CORRUPTED,
1076 MZ_ZIP_UNSUPPORTED_MULTIDISK,
1077 MZ_ZIP_DECOMPRESSION_FAILED,
1078 MZ_ZIP_COMPRESSION_FAILED,
1079 MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE,
1080 MZ_ZIP_CRC_CHECK_FAILED,
1081 MZ_ZIP_UNSUPPORTED_CDIR_SIZE,
1082 MZ_ZIP_ALLOC_FAILED,
1083 MZ_ZIP_FILE_OPEN_FAILED,
1084 MZ_ZIP_FILE_CREATE_FAILED,
1085 MZ_ZIP_FILE_WRITE_FAILED,
1086 MZ_ZIP_FILE_READ_FAILED,
1087 MZ_ZIP_FILE_CLOSE_FAILED,
1088 MZ_ZIP_FILE_SEEK_FAILED,
1089 MZ_ZIP_FILE_STAT_FAILED,
1090 MZ_ZIP_INVALID_PARAMETER,
1091 MZ_ZIP_INVALID_FILENAME,
1092 MZ_ZIP_BUF_TOO_SMALL,
1093 MZ_ZIP_INTERNAL_ERROR,
1094 MZ_ZIP_FILE_NOT_FOUND,
1095 MZ_ZIP_ARCHIVE_TOO_LARGE,
1096 MZ_ZIP_VALIDATION_FAILED,
1097 MZ_ZIP_WRITE_CALLBACK_FAILED,
1098 MZ_ZIP_TOTAL_ERRORS
1099} mz_zip_error;
1100
1101typedef struct
1102{
1103 mz_uint64 m_archive_size;
1104 mz_uint64 m_central_directory_file_ofs;
1105
1106 /* We only support up to UINT32_MAX files in zip64 mode. */
1107 mz_uint32 m_total_files;
1108 mz_zip_mode m_zip_mode;
1109 mz_zip_type m_zip_type;
1110 mz_zip_error m_last_error;
1111
1112 mz_uint64 m_file_offset_alignment;
1113
1114 mz_alloc_func m_pAlloc;
1115 mz_free_func m_pFree;
1116 mz_realloc_func m_pRealloc;
1117 void* m_pAlloc_opaque;
1118
1119 mz_file_read_func m_pRead;
1120 mz_file_write_func m_pWrite;
1121 mz_file_needs_keepalive m_pNeeds_keepalive;
1122 void* m_pIO_opaque;
1123
1124 mz_zip_internal_state* m_pState;
1125
1126} mz_zip_archive;
1127
1128typedef struct
1129{
1130 mz_zip_archive* pZip;
1131 mz_uint flags;
1132
1133 int status;
1134
1135 mz_uint64 read_buf_size, read_buf_ofs, read_buf_avail, comp_remaining, out_buf_ofs, cur_file_ofs;
1136 mz_zip_archive_file_stat file_stat;
1137 void* pRead_buf;
1138 void* pWrite_buf;
1139
1140 size_t out_blk_remain;
1141
1142 tinfl_decompressor inflator;
1143
1144#ifdef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
1145 mz_uint padding;
1146#else
1147 mz_uint file_crc32;
1148#endif
1149
1150} mz_zip_reader_extract_iter_state;
1151
1152/* -------- ZIP reading */
1153
1154/* Inits a ZIP archive reader. */
1155/* These functions read and validate the archive's central directory. */
1156MINIZ_EXPORT mz_bool mz_zip_reader_init(mz_zip_archive* pZip, mz_uint64 size, mz_uint flags);
1157
1158MINIZ_EXPORT mz_bool mz_zip_reader_init_mem(mz_zip_archive* pZip, const void* pMem, size_t size, mz_uint flags);
1159
1160#ifndef MINIZ_NO_STDIO
1161/* Read a archive from a disk file. */
1162/* file_start_ofs is the file offset where the archive actually begins, or 0. */
1163/* actual_archive_size is the true total size of the archive, which may be smaller than the file's actual size on disk. If zero the entire file is treated as the archive. */
1164MINIZ_EXPORT mz_bool mz_zip_reader_init_file(mz_zip_archive* pZip, const char* pFilename, mz_uint32 flags);
1165MINIZ_EXPORT mz_bool mz_zip_reader_init_file_v2(mz_zip_archive* pZip, const char* pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size);
1166
1167/* Read an archive from an already opened FILE, beginning at the current file position. */
1168/* The archive is assumed to be archive_size bytes long. If archive_size is 0, then the entire rest of the file is assumed to contain the archive. */
1169/* The FILE will NOT be closed when mz_zip_reader_end() is called. */
1170MINIZ_EXPORT mz_bool mz_zip_reader_init_cfile(mz_zip_archive* pZip, MZ_FILE* pFile, mz_uint64 archive_size, mz_uint flags);
1171#endif
1172
1173/* Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used. */
1174MINIZ_EXPORT mz_bool mz_zip_reader_end(mz_zip_archive* pZip);
1175
1176/* -------- ZIP reading or writing */
1177
1178/* Clears a mz_zip_archive struct to all zeros. */
1179/* Important: This must be done before passing the struct to any mz_zip functions. */
1180MINIZ_EXPORT void mz_zip_zero_struct(mz_zip_archive* pZip);
1181
1182MINIZ_EXPORT mz_zip_mode mz_zip_get_mode(mz_zip_archive* pZip);
1183MINIZ_EXPORT mz_zip_type mz_zip_get_type(mz_zip_archive* pZip);
1184
1185/* Returns the total number of files in the archive. */
1186MINIZ_EXPORT mz_uint mz_zip_reader_get_num_files(mz_zip_archive* pZip);
1187
1188MINIZ_EXPORT mz_uint64 mz_zip_get_archive_size(mz_zip_archive* pZip);
1189MINIZ_EXPORT mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive* pZip);
1190MINIZ_EXPORT MZ_FILE* mz_zip_get_cfile(mz_zip_archive* pZip);
1191
1192/* Reads n bytes of raw archive data, starting at file offset file_ofs, to pBuf. */
1193MINIZ_EXPORT size_t mz_zip_read_archive_data(mz_zip_archive* pZip, mz_uint64 file_ofs, void* pBuf, size_t n);
1194
1195/* All mz_zip funcs set the m_last_error field in the mz_zip_archive struct. These functions retrieve/manipulate this field. */
1196/* Note that the m_last_error functionality is not thread safe. */
1197MINIZ_EXPORT mz_zip_error mz_zip_set_last_error(mz_zip_archive* pZip, mz_zip_error err_num);
1198MINIZ_EXPORT mz_zip_error mz_zip_peek_last_error(mz_zip_archive* pZip);
1199MINIZ_EXPORT mz_zip_error mz_zip_clear_last_error(mz_zip_archive* pZip);
1200MINIZ_EXPORT mz_zip_error mz_zip_get_last_error(mz_zip_archive* pZip);
1201MINIZ_EXPORT const char* mz_zip_get_error_string(mz_zip_error mz_err);
1202
1203/* MZ_TRUE if the archive file entry is a directory entry. */
1204MINIZ_EXPORT mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive* pZip, mz_uint file_index);
1205
1206/* MZ_TRUE if the file is encrypted/strong encrypted. */
1207MINIZ_EXPORT mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive* pZip, mz_uint file_index);
1208
1209/* MZ_TRUE if the compression method is supported, and the file is not encrypted, and the file is not a compressed patch file. */
1210MINIZ_EXPORT mz_bool mz_zip_reader_is_file_supported(mz_zip_archive* pZip, mz_uint file_index);
1211
1212/* Retrieves the filename of an archive file entry. */
1213/* 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. */
1214MINIZ_EXPORT mz_uint mz_zip_reader_get_filename(mz_zip_archive* pZip, mz_uint file_index, char* pFilename, mz_uint filename_buf_size);
1215
1216/* Attempts to locates a file in the archive's central directory. */
1217/* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */
1218/* Returns -1 if the file cannot be found. */
1219MINIZ_EXPORT int mz_zip_reader_locate_file(mz_zip_archive* pZip, const char* pName, const char* pComment, mz_uint flags);
1220MINIZ_EXPORT mz_bool mz_zip_reader_locate_file_v2(mz_zip_archive* pZip, const char* pName, const char* pComment, mz_uint flags, mz_uint32* file_index);
1221
1222/* Returns detailed information about an archive file entry. */
1223MINIZ_EXPORT mz_bool mz_zip_reader_file_stat(mz_zip_archive* pZip, mz_uint file_index, mz_zip_archive_file_stat* pStat);
1224
1225/* MZ_TRUE if the file is in zip64 format. */
1226/* A file is considered zip64 if it contained a zip64 end of central directory marker, or if it contained any zip64 extended file information fields in the central directory. */
1227MINIZ_EXPORT mz_bool mz_zip_is_zip64(mz_zip_archive* pZip);
1228
1229/* Returns the total central directory size in bytes. */
1230/* The current max supported size is <= MZ_UINT32_MAX. */
1231MINIZ_EXPORT size_t mz_zip_get_central_dir_size(mz_zip_archive* pZip);
1232
1233/* Extracts a archive file to a memory buffer using no memory allocation. */
1234/* There must be at least enough room on the stack to store the inflator's state (~34KB or so). */
1235MINIZ_EXPORT 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);
1236MINIZ_EXPORT 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);
1237
1238/* Extracts a archive file to a memory buffer. */
1239MINIZ_EXPORT 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);
1240MINIZ_EXPORT 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);
1241
1242/* Extracts a archive file to a dynamically allocated heap buffer. */
1243/* The memory will be allocated via the mz_zip_archive's alloc/realloc functions. */
1244/* Returns NULL and sets the last error on failure. */
1245MINIZ_EXPORT void* mz_zip_reader_extract_to_heap(mz_zip_archive* pZip, mz_uint file_index, size_t* pSize, mz_uint flags);
1246MINIZ_EXPORT void* mz_zip_reader_extract_file_to_heap(mz_zip_archive* pZip, const char* pFilename, size_t* pSize, mz_uint flags);
1247
1248/* Extracts a archive file using a callback function to output the file's data. */
1249MINIZ_EXPORT 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);
1250MINIZ_EXPORT 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);
1251
1252/* Extract a file iteratively */
1253MINIZ_EXPORT mz_zip_reader_extract_iter_state* mz_zip_reader_extract_iter_new(mz_zip_archive* pZip, mz_uint file_index, mz_uint flags);
1254MINIZ_EXPORT mz_zip_reader_extract_iter_state* mz_zip_reader_extract_file_iter_new(mz_zip_archive* pZip, const char* pFilename, mz_uint flags);
1255MINIZ_EXPORT size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state* pState, void* pvBuf, size_t buf_size);
1256MINIZ_EXPORT mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state* pState);
1257
1258#ifndef MINIZ_NO_STDIO
1259/* Extracts a archive file to a disk file and sets its last accessed and modified times. */
1260/* This function only extracts files, not archive directory records. */
1261MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_file(mz_zip_archive* pZip, mz_uint file_index, const char* pDst_filename, mz_uint flags);
1262MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive* pZip, const char* pArchive_filename, const char* pDst_filename, mz_uint flags);
1263
1264/* Extracts a archive file starting at the current position in the destination FILE stream. */
1265MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive* pZip, mz_uint file_index, MZ_FILE* File, mz_uint flags);
1266MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive* pZip, const char* pArchive_filename, MZ_FILE* pFile, mz_uint flags);
1267#endif
1268
1269#if 0
1270/* TODO */
1271 typedef void *mz_zip_streaming_extract_state_ptr;
1272 mz_zip_streaming_extract_state_ptr mz_zip_streaming_extract_begin(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
1273 mz_uint64 mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
1274 mz_uint64 mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
1275 mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, mz_uint64 new_ofs);
1276 size_t mz_zip_streaming_extract_read(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, void *pBuf, size_t buf_size);
1277 mz_bool mz_zip_streaming_extract_end(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
1278#endif
1279
1280/* This function compares the archive's local headers, the optional local zip64 extended information block, and the optional descriptor following the compressed data vs. the data in the central directory. */
1281/* It also validates that each file can be successfully uncompressed unless the MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY is specified. */
1282MINIZ_EXPORT mz_bool mz_zip_validate_file(mz_zip_archive* pZip, mz_uint file_index, mz_uint flags);
1283
1284/* Validates an entire archive by calling mz_zip_validate_file() on each file. */
1285MINIZ_EXPORT mz_bool mz_zip_validate_archive(mz_zip_archive* pZip, mz_uint flags);
1286
1287/* Misc utils/helpers, valid for ZIP reading or writing */
1288MINIZ_EXPORT mz_bool mz_zip_validate_mem_archive(const void* pMem, size_t size, mz_uint flags, mz_zip_error* pErr);
1289#ifndef MINIZ_NO_STDIO
1290MINIZ_EXPORT mz_bool mz_zip_validate_file_archive(const char* pFilename, mz_uint flags, mz_zip_error* pErr);
1291#endif
1292
1293/* Universal end function - calls either mz_zip_reader_end() or mz_zip_writer_end(). */
1294MINIZ_EXPORT mz_bool mz_zip_end(mz_zip_archive* pZip);
1295
1296/* -------- ZIP writing */
1297
1298#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
1299
1300/* Inits a ZIP archive writer. */
1301/*Set pZip->m_pWrite (and pZip->m_pIO_opaque) before calling mz_zip_writer_init or mz_zip_writer_init_v2*/
1302/*The output is streamable, i.e. file_ofs in mz_file_write_func always increases only by n*/
1303MINIZ_EXPORT mz_bool mz_zip_writer_init(mz_zip_archive* pZip, mz_uint64 existing_size);
1304MINIZ_EXPORT mz_bool mz_zip_writer_init_v2(mz_zip_archive* pZip, mz_uint64 existing_size, mz_uint flags);
1305
1306MINIZ_EXPORT mz_bool mz_zip_writer_init_heap(mz_zip_archive* pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
1307MINIZ_EXPORT mz_bool mz_zip_writer_init_heap_v2(mz_zip_archive* pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags);
1308
1309#ifndef MINIZ_NO_STDIO
1310MINIZ_EXPORT mz_bool mz_zip_writer_init_file(mz_zip_archive* pZip, const char* pFilename, mz_uint64 size_to_reserve_at_beginning);
1311MINIZ_EXPORT mz_bool mz_zip_writer_init_file_v2(mz_zip_archive* pZip, const char* pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags);
1312MINIZ_EXPORT mz_bool mz_zip_writer_init_cfile(mz_zip_archive* pZip, MZ_FILE* pFile, mz_uint flags);
1313#endif
1314
1315/* Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive. */
1316/* 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. */
1317/* 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). */
1318/* Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL. */
1319/* Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before */
1320/* the archive is finalized the file's central directory will be hosed. */
1321MINIZ_EXPORT mz_bool mz_zip_writer_init_from_reader(mz_zip_archive* pZip, const char* pFilename);
1322MINIZ_EXPORT mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive* pZip, const char* pFilename, mz_uint flags);
1323
1324/* Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive. */
1325/* To add a directory entry, call this method with an archive name ending in a forwardslash with an empty buffer. */
1326/* 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. */
1327MINIZ_EXPORT 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);
1328
1329/* Like mz_zip_writer_add_mem(), except you can specify a file comment field, and optionally supply the function with already compressed data. */
1330/* uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA flag is specified. */
1331MINIZ_EXPORT 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,
1332 mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
1333
1334MINIZ_EXPORT mz_bool mz_zip_writer_add_mem_ex_v2(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,
1335 mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T* last_modified, const char* user_extra_data_local, mz_uint user_extra_data_local_len,
1336 const char* user_extra_data_central, mz_uint user_extra_data_central_len);
1337
1338/* Adds the contents of a file to an archive. This function also records the disk file's modified time into the archive. */
1339/* File data is supplied via a read callback function. User mz_zip_writer_add_(c)file to add a file directly.*/
1340MINIZ_EXPORT mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive* pZip, const char* pArchive_name, mz_file_read_func read_callback, void* callback_opaque, mz_uint64 max_size,
1341 const MZ_TIME_T* pFile_time, const void* pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char* user_extra_data_local, mz_uint user_extra_data_local_len,
1342 const char* user_extra_data_central, mz_uint user_extra_data_central_len);
1343
1344#ifndef MINIZ_NO_STDIO
1345/* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */
1346/* 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. */
1347MINIZ_EXPORT 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);
1348
1349/* Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream. */
1350MINIZ_EXPORT mz_bool mz_zip_writer_add_cfile(mz_zip_archive* pZip, const char* pArchive_name, MZ_FILE* pSrc_file, mz_uint64 max_size,
1351 const MZ_TIME_T* pFile_time, const void* pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char* user_extra_data_local, mz_uint user_extra_data_local_len,
1352 const char* user_extra_data_central, mz_uint user_extra_data_central_len);
1353#endif
1354
1355/* Adds a file to an archive by fully cloning the data from another archive. */
1356/* This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data (it may add or modify the zip64 local header extra data field), and the optional descriptor following the compressed data. */
1357MINIZ_EXPORT mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive* pZip, mz_zip_archive* pSource_zip, mz_uint src_file_index);
1358
1359/* Finalizes the archive by writing the central directory records followed by the end of central directory record. */
1360/* After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end(). */
1361/* An archive must be manually finalized by calling this function for it to be valid. */
1362MINIZ_EXPORT mz_bool mz_zip_writer_finalize_archive(mz_zip_archive* pZip);
1363
1364/* Finalizes a heap archive, returning a pointer to the heap block and its size. */
1365/* The heap block will be allocated using the mz_zip_archive's alloc/realloc callbacks. */
1366MINIZ_EXPORT mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive* pZip, void** ppBuf, size_t* pSize);
1367
1368/* Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used. */
1369/* Note for the archive to be valid, it *must* have been finalized before ending (this function will not do it for you). */
1370MINIZ_EXPORT mz_bool mz_zip_writer_end(mz_zip_archive* pZip);
1371
1372/* -------- Misc. high-level helper functions: */
1373
1374/* mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive. */
1375/* Note this is NOT a fully safe operation. If it crashes or dies in some way your archive can be left in a screwed up state (without a central directory). */
1376/* 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. */
1377/* TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate the file (so the old central dir would be at the end) if something goes wrong. */
1378MINIZ_EXPORT 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);
1379MINIZ_EXPORT mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(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, mz_zip_error* pErr);
1380
1381#ifndef MINIZ_NO_STDIO
1382/* Reads a single file from an archive into a heap block. */
1383/* If pComment is not NULL, only the file with the specified comment will be extracted. */
1384/* Returns NULL on failure. */
1385MINIZ_EXPORT void* mz_zip_extract_archive_file_to_heap(const char* pZip_filename, const char* pArchive_name, size_t* pSize, mz_uint flags);
1386MINIZ_EXPORT void* mz_zip_extract_archive_file_to_heap_v2(const char* pZip_filename, const char* pArchive_name, const char* pComment, size_t* pSize, mz_uint flags, mz_zip_error* pErr);
1387#endif
1388
1389#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */
1390
1391#ifdef __cplusplus
1392}
1393#endif
1394
1395#endif /* MINIZ_NO_ARCHIVE_APIS */
voidpf void uLong size
Definition ioapi.h:126
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
mz_bool mz_zip_is_zip64(mz_zip_archive *pZip)
Definition miniz.c:7094
mz_bool mz_zip_reader_end(mz_zip_archive *pZip)
Definition miniz.c:3640
mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags)
Definition miniz.c:5055
mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip)
Definition miniz.c:6720
mz_zip_type mz_zip_get_type(mz_zip_archive *pZip)
Definition miniz.c:6973
mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pArchive_name, mz_file_read_func read_callback, void *callback_opaque, mz_uint64 max_size, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len)
Definition miniz.c:5954
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)
Definition miniz.c:1861
mz_bool mz_zip_end(mz_zip_archive *pZip)
Definition miniz.c:7168
mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip)
Definition miniz.c:7110
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)
Definition miniz.c:1965
mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning)
Definition miniz.c:5377
void * tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
Definition miniz.c:1906
mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags)
Definition miniz.c:3718
size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip)
Definition miniz.c:7102
mz_uint32 tdefl_get_adler32(tdefl_compressor *d)
Definition miniz.c:1856
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)
Definition miniz.c:4506
mz_zip_reader_extract_iter_state * mz_zip_reader_extract_iter_new(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags)
Definition miniz.c:4515
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)
Definition miniz.c:6834
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)
Definition miniz.c:1921
mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip)
Definition miniz.c:6968
MINIZ_EXPORT void * miniz_def_alloc_func(void *opaque, size_t items, size_t size)
Definition miniz.c:161
tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
Definition miniz.c:1815
MINIZ_EXPORT void * miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size)
Definition miniz.c:171
size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n)
Definition miniz.c:7136
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)
Definition miniz.c:2693
mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags)
Definition miniz.c:5382
mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index)
Definition miniz.c:3864
void * tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
Definition miniz.c:2649
mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(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, mz_zip_error *pErr)
Definition miniz.c:6839
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)
Definition miniz.c:4267
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)
Definition miniz.c:5698
mz_bool mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *pIndex)
Definition miniz.c:4078
tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d)
Definition miniz.c:1851
mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size)
Definition miniz.c:5356
mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip)
Definition miniz.c:6991
mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint flags)
Definition miniz.c:3644
mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip)
Definition miniz.c:7004
mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags)
Definition miniz.c:4822
tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush)
Definition miniz.c:1809
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)
Definition miniz.c:4334
mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr)
Definition miniz.c:5138
mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags)
Definition miniz.c:3671
void * mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr)
Definition miniz.c:6921
const char * mz_zip_get_error_string(mz_zip_error mz_err)
Definition miniz.c:7017
void * mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags)
Definition miniz.c:4290
mz_bool mz_zip_writer_end(mz_zip_archive *pZip)
Definition miniz.c:6828
mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags)
Definition miniz.c:5425
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)
Definition miniz.c:6292
int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags)
Definition miniz.c:4069
mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index)
Definition miniz.c:3819
mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size)
Definition miniz.c:5325
void mz_zip_zero_struct(mz_zip_archive *pZip)
Definition miniz.c:3592
mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip)
Definition miniz.c:7115
size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state *pState, void *pvBuf, size_t buf_size)
Definition miniz.c:4639
MZ_FILE * mz_zip_get_cfile(mz_zip_archive *pZip)
Definition miniz.c:7129
mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index)
Definition miniz.c:6396
mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index)
Definition miniz.c:3832
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)
Definition miniz.c:4280
mz_zip_error mz_zip_set_last_error(mz_zip_archive *pZip, mz_zip_error err_num)
Definition miniz.c:6978
MINIZ_EXPORT void miniz_def_free_func(void *opaque, void *address)
Definition miniz.c:166
tinfl_decompressor * tinfl_decompressor_alloc(void)
Definition miniz.c:2722
mz_zip_reader_extract_iter_state * mz_zip_reader_extract_file_iter_new(mz_zip_archive *pZip, const char *pFilename, mz_uint flags)
Definition miniz.c:4627
void * mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags)
Definition miniz.c:6957
mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat)
Definition miniz.c:7163
mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags)
Definition miniz.c:5446
mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size)
Definition miniz.c:3723
void tdefl_compressor_free(tdefl_compressor *pComp)
Definition miniz.c:2054
mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip)
Definition miniz.c:7122
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)
Definition miniz.c:5530
void * mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags)
Definition miniz.c:4323
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)
Definition miniz.c:4285
mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 max_size, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len)
Definition miniz.c:6285
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)
Definition miniz.c:4272
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)
Definition miniz.c:2684
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)
Definition miniz.c:2229
tdefl_compressor * tdefl_compressor_alloc(void)
Definition miniz.c:2049
mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr)
Definition miniz.c:5100
mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags)
Definition miniz.c:4862
void * tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out)
Definition miniz.c:2039
mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy)
Definition miniz.c:1937
mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state *pState)
Definition miniz.c:4743
mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *pFile, mz_uint flags)
Definition miniz.c:4831
mz_bool mz_zip_reader_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint64 archive_size, mz_uint flags)
Definition miniz.c:3772
mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **ppBuf, size_t *pSize)
Definition miniz.c:6803
mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags)
Definition miniz.c:4844
mz_bool mz_zip_writer_init_v2(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags)
Definition miniz.c:5278
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)
Definition miniz.c:1750
mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename)
Definition miniz.c:5524
mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip)
Definition miniz.c:6999
mz_bool mz_zip_writer_add_mem_ex_v2(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, MZ_TIME_T *last_modified, const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len)
Definition miniz.c:5704
mz_bool mz_zip_writer_init_heap_v2(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags)
Definition miniz.c:5330
mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags)
Definition miniz.c:4789
mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size)
Definition miniz.c:7144
void tinfl_decompressor_free(tinfl_decompressor *pDecomp)
Definition miniz.c:2730
MINIZ_EXPORT int mz_inflateInit(mz_streamp pStream)
Definition miniz.c:393
unsigned long mz_ulong
Definition miniz.h:233
MINIZ_EXPORT mz_ulong mz_compressBound(mz_ulong source_len)
Definition miniz.c:339
void *(* mz_alloc_func)(void *opaque, size_t items, size_t size)
Definition miniz.h:260
MINIZ_EXPORT int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
Definition miniz.c:334
mz_ulong uLong
Definition miniz.h:440
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)
Definition miniz.c:191
MINIZ_EXPORT int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
Definition miniz.c:570
MINIZ_EXPORT int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level)
Definition miniz.c:305
MINIZ_EXPORT int mz_deflateEnd(mz_streamp pStream)
Definition miniz.c:287
MINIZ_EXPORT const char * mz_error(int err)
Definition miniz.c:577
MINIZ_EXPORT int mz_inflateEnd(mz_streamp pStream)
Definition miniz.c:530
MINIZ_EXPORT mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
Definition miniz.c:39
MINIZ_EXPORT mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len)
MINIZ_EXPORT int mz_deflateInit(mz_streamp pStream, int level)
Definition miniz.c:186
@ MZ_FILTERED
Definition miniz.h:249
@ MZ_FIXED
Definition miniz.h:252
@ MZ_DEFAULT_STRATEGY
Definition miniz.h:248
@ MZ_RLE
Definition miniz.h:251
@ MZ_HUFFMAN_ONLY
Definition miniz.h:250
@ MZ_MEM_ERROR
Definition miniz.h:301
@ MZ_PARAM_ERROR
Definition miniz.h:304
@ MZ_NEED_DICT
Definition miniz.h:297
@ MZ_VERSION_ERROR
Definition miniz.h:303
@ MZ_STREAM_END
Definition miniz.h:296
@ MZ_ERRNO
Definition miniz.h:298
@ MZ_OK
Definition miniz.h:295
@ MZ_BUF_ERROR
Definition miniz.h:302
@ MZ_STREAM_ERROR
Definition miniz.h:299
@ MZ_DATA_ERROR
Definition miniz.h:300
@ MZ_BEST_SPEED
Definition miniz.h:267
@ MZ_NO_COMPRESSION
Definition miniz.h:266
@ MZ_UBER_COMPRESSION
Definition miniz.h:269
@ MZ_DEFAULT_LEVEL
Definition miniz.h:270
@ MZ_BEST_COMPRESSION
Definition miniz.h:268
@ MZ_DEFAULT_COMPRESSION
Definition miniz.h:271
void * voidpf
Definition miniz.h:445
int intf
Definition miniz.h:444
uInt uIntf
Definition miniz.h:442
char charf
Definition miniz.h:443
unsigned int uInt
Definition miniz.h:439
MINIZ_EXPORT int mz_inflate(mz_streamp pStream, int flush)
Definition miniz.c:424
MINIZ_EXPORT mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len)
Definition miniz.c:298
MINIZ_EXPORT void mz_free(void *p)
Definition miniz.c:156
MINIZ_EXPORT int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len)
Definition miniz.c:540
MINIZ_EXPORT int mz_deflate(mz_streamp pStream, int flush)
Definition miniz.c:235
void *(* mz_realloc_func)(void *opaque, void *address, size_t items, size_t size)
Definition miniz.h:262
void(* mz_free_func)(void *opaque, void *address)
Definition miniz.h:261
Byte Bytef
Definition miniz.h:441
MINIZ_EXPORT const char * mz_version(void)
Definition miniz.c:177
uLong uLongf
Definition miniz.h:446
MINIZ_EXPORT int mz_inflateReset(mz_streamp pStream)
Definition miniz.c:398
MINIZ_EXPORT int mz_inflateInit2(mz_streamp pStream, int window_bits)
Definition miniz.c:357
unsigned char Byte
Definition miniz.h:438
@ MZ_SYNC_FLUSH
Definition miniz.h:287
@ MZ_BLOCK
Definition miniz.h:290
@ MZ_FULL_FLUSH
Definition miniz.h:288
@ MZ_FINISH
Definition miniz.h:289
@ MZ_PARTIAL_FLUSH
Definition miniz.h:286
@ MZ_NO_FLUSH
Definition miniz.h:285
mz_stream * mz_streamp
Definition miniz.h:334
MINIZ_EXPORT int mz_deflateReset(mz_streamp pStream)
Definition miniz.c:226
void * voidp
Definition miniz.h:447
void *const voidpc
Definition miniz.h:448
mz_ulong adler
Definition miniz.h:330
unsigned char * next_out
Definition miniz.h:318
void * opaque
Definition miniz.h:327
int data_type
Definition miniz.h:329
mz_free_func zfree
Definition miniz.h:326
mz_ulong total_out
Definition miniz.h:320
unsigned int avail_out
Definition miniz.h:319
struct mz_internal_state * state
Definition miniz.h:323
const unsigned char * next_in
Definition miniz.h:314
unsigned int avail_in
Definition miniz.h:315
mz_alloc_func zalloc
Definition miniz.h:325
mz_ulong total_in
Definition miniz.h:316
char * msg
Definition miniz.h:322
mz_ulong reserved
Definition miniz.h:331