xref: /aosp_15_r20/external/OpenCL-CTS/test_common/miniz/miniz.h (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
1*6467f958SSadaf Ebrahimi #ifndef MINIZ_HEADER_INCLUDED
2*6467f958SSadaf Ebrahimi #define MINIZ_HEADER_INCLUDED
3*6467f958SSadaf Ebrahimi 
4*6467f958SSadaf Ebrahimi #include <stdlib.h>
5*6467f958SSadaf Ebrahimi 
6*6467f958SSadaf Ebrahimi #if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
7*6467f958SSadaf Ebrahimi   // TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux
8*6467f958SSadaf Ebrahimi   #define MINIZ_NO_TIME
9*6467f958SSadaf Ebrahimi #endif
10*6467f958SSadaf Ebrahimi 
11*6467f958SSadaf Ebrahimi #if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
12*6467f958SSadaf Ebrahimi   #include <time.h>
13*6467f958SSadaf Ebrahimi #endif
14*6467f958SSadaf Ebrahimi 
15*6467f958SSadaf Ebrahimi #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
16*6467f958SSadaf Ebrahimi // MINIZ_X86_OR_X64_CPU is only used to help set the below macros.
17*6467f958SSadaf Ebrahimi #define MINIZ_X86_OR_X64_CPU 1
18*6467f958SSadaf Ebrahimi #endif
19*6467f958SSadaf Ebrahimi 
20*6467f958SSadaf Ebrahimi #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
21*6467f958SSadaf Ebrahimi // Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian.
22*6467f958SSadaf Ebrahimi #define MINIZ_LITTLE_ENDIAN 1
23*6467f958SSadaf Ebrahimi #endif
24*6467f958SSadaf Ebrahimi 
25*6467f958SSadaf Ebrahimi #if MINIZ_X86_OR_X64_CPU
26*6467f958SSadaf Ebrahimi // Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses.
27*6467f958SSadaf Ebrahimi #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
28*6467f958SSadaf Ebrahimi #endif
29*6467f958SSadaf Ebrahimi 
30*6467f958SSadaf Ebrahimi #if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
31*6467f958SSadaf Ebrahimi // 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).
32*6467f958SSadaf Ebrahimi #define MINIZ_HAS_64BIT_REGISTERS 1
33*6467f958SSadaf Ebrahimi #endif
34*6467f958SSadaf Ebrahimi 
35*6467f958SSadaf Ebrahimi // Return status codes. MZ_PARAM_ERROR is non-standard.
36*6467f958SSadaf Ebrahimi enum {
37*6467f958SSadaf Ebrahimi   MZ_OK = 0,
38*6467f958SSadaf Ebrahimi   MZ_STREAM_END = 1,
39*6467f958SSadaf Ebrahimi   MZ_NEED_DICT = 2,
40*6467f958SSadaf Ebrahimi   MZ_ERRNO = -1,
41*6467f958SSadaf Ebrahimi   MZ_STREAM_ERROR = -2,
42*6467f958SSadaf Ebrahimi   MZ_DATA_ERROR = -3,
43*6467f958SSadaf Ebrahimi   MZ_MEM_ERROR = -4,
44*6467f958SSadaf Ebrahimi   MZ_BUF_ERROR = -5,
45*6467f958SSadaf Ebrahimi   MZ_VERSION_ERROR = -6,
46*6467f958SSadaf Ebrahimi   MZ_PARAM_ERROR = -10000
47*6467f958SSadaf Ebrahimi };
48*6467f958SSadaf Ebrahimi 
49*6467f958SSadaf Ebrahimi typedef unsigned long mz_ulong;
50*6467f958SSadaf Ebrahimi 
51*6467f958SSadaf Ebrahimi #ifdef __cplusplus
52*6467f958SSadaf Ebrahimi extern "C" {
53*6467f958SSadaf Ebrahimi #endif
54*6467f958SSadaf Ebrahimi 
55*6467f958SSadaf Ebrahimi // ------------------- zlib-style API Definitions.
56*6467f958SSadaf Ebrahimi 
57*6467f958SSadaf Ebrahimi // 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.
58*6467f958SSadaf Ebrahimi void mz_free(void *p);
59*6467f958SSadaf Ebrahimi 
60*6467f958SSadaf Ebrahimi #define MZ_ADLER32_INIT (1)
61*6467f958SSadaf Ebrahimi // mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
62*6467f958SSadaf Ebrahimi mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
63*6467f958SSadaf Ebrahimi 
64*6467f958SSadaf Ebrahimi #define MZ_CRC32_INIT (0)
65*6467f958SSadaf Ebrahimi // mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL.
66*6467f958SSadaf Ebrahimi mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
67*6467f958SSadaf Ebrahimi 
68*6467f958SSadaf Ebrahimi // Compression strategies.
69*6467f958SSadaf Ebrahimi enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 };
70*6467f958SSadaf Ebrahimi 
71*6467f958SSadaf Ebrahimi // Method
72*6467f958SSadaf Ebrahimi #define MZ_DEFLATED 8
73*6467f958SSadaf Ebrahimi 
74*6467f958SSadaf Ebrahimi #ifndef MINIZ_NO_ZLIB_APIS
75*6467f958SSadaf Ebrahimi 
76*6467f958SSadaf Ebrahimi // Heap allocation callbacks.
77*6467f958SSadaf Ebrahimi // Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long.
78*6467f958SSadaf Ebrahimi typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
79*6467f958SSadaf Ebrahimi typedef void (*mz_free_func)(void *opaque, void *address);
80*6467f958SSadaf Ebrahimi typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
81*6467f958SSadaf Ebrahimi 
82*6467f958SSadaf Ebrahimi #define MZ_VERSION          "9.1.15"
83*6467f958SSadaf Ebrahimi #define MZ_VERNUM           0x91F0
84*6467f958SSadaf Ebrahimi #define MZ_VER_MAJOR        9
85*6467f958SSadaf Ebrahimi #define MZ_VER_MINOR        1
86*6467f958SSadaf Ebrahimi #define MZ_VER_REVISION     15
87*6467f958SSadaf Ebrahimi #define MZ_VER_SUBREVISION  0
88*6467f958SSadaf Ebrahimi 
89*6467f958SSadaf Ebrahimi // 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).
90*6467f958SSadaf Ebrahimi enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
91*6467f958SSadaf Ebrahimi 
92*6467f958SSadaf Ebrahimi // 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.
93*6467f958SSadaf Ebrahimi enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 };
94*6467f958SSadaf Ebrahimi 
95*6467f958SSadaf Ebrahimi // Window bits
96*6467f958SSadaf Ebrahimi #define MZ_DEFAULT_WINDOW_BITS 15
97*6467f958SSadaf Ebrahimi 
98*6467f958SSadaf Ebrahimi struct mz_internal_state;
99*6467f958SSadaf Ebrahimi 
100*6467f958SSadaf Ebrahimi // Compression/decompression stream struct.
101*6467f958SSadaf Ebrahimi typedef struct mz_stream_s
102*6467f958SSadaf Ebrahimi {
103*6467f958SSadaf Ebrahimi   const unsigned char *next_in;     // pointer to next byte to read
104*6467f958SSadaf Ebrahimi   unsigned int avail_in;            // number of bytes available at next_in
105*6467f958SSadaf Ebrahimi   mz_ulong total_in;                // total number of bytes consumed so far
106*6467f958SSadaf Ebrahimi 
107*6467f958SSadaf Ebrahimi   unsigned char *next_out;          // pointer to next byte to write
108*6467f958SSadaf Ebrahimi   unsigned int avail_out;           // number of bytes that can be written to next_out
109*6467f958SSadaf Ebrahimi   mz_ulong total_out;               // total number of bytes produced so far
110*6467f958SSadaf Ebrahimi 
111*6467f958SSadaf Ebrahimi   char *msg;                        // error msg (unused)
112*6467f958SSadaf Ebrahimi   struct mz_internal_state *state;  // internal state, allocated by zalloc/zfree
113*6467f958SSadaf Ebrahimi 
114*6467f958SSadaf Ebrahimi   mz_alloc_func zalloc;             // optional heap allocation function (defaults to malloc)
115*6467f958SSadaf Ebrahimi   mz_free_func zfree;               // optional heap free function (defaults to free)
116*6467f958SSadaf Ebrahimi   void *opaque;                     // heap alloc function user pointer
117*6467f958SSadaf Ebrahimi 
118*6467f958SSadaf Ebrahimi   int data_type;                    // data_type (unused)
119*6467f958SSadaf Ebrahimi   mz_ulong adler;                   // adler32 of the source or uncompressed data
120*6467f958SSadaf Ebrahimi   mz_ulong reserved;                // not used
121*6467f958SSadaf Ebrahimi } mz_stream;
122*6467f958SSadaf Ebrahimi 
123*6467f958SSadaf Ebrahimi typedef mz_stream *mz_streamp;
124*6467f958SSadaf Ebrahimi 
125*6467f958SSadaf Ebrahimi // Returns the version string of miniz.c.
126*6467f958SSadaf Ebrahimi const char *mz_version(void);
127*6467f958SSadaf Ebrahimi 
128*6467f958SSadaf Ebrahimi // mz_deflateInit() initializes a compressor with default options:
129*6467f958SSadaf Ebrahimi // Parameters:
130*6467f958SSadaf Ebrahimi //  pStream must point to an initialized mz_stream struct.
131*6467f958SSadaf Ebrahimi //  level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION].
132*6467f958SSadaf Ebrahimi //  level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
133*6467f958SSadaf Ebrahimi //  (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.)
134*6467f958SSadaf Ebrahimi // Return values:
135*6467f958SSadaf Ebrahimi //  MZ_OK on success.
136*6467f958SSadaf Ebrahimi //  MZ_STREAM_ERROR if the stream is bogus.
137*6467f958SSadaf Ebrahimi //  MZ_PARAM_ERROR if the input parameters are bogus.
138*6467f958SSadaf Ebrahimi //  MZ_MEM_ERROR on out of memory.
139*6467f958SSadaf Ebrahimi int mz_deflateInit(mz_streamp pStream, int level);
140*6467f958SSadaf Ebrahimi 
141*6467f958SSadaf Ebrahimi // mz_deflateInit2() is like mz_deflate(), except with more control:
142*6467f958SSadaf Ebrahimi // Additional parameters:
143*6467f958SSadaf Ebrahimi //   method must be MZ_DEFLATED
144*6467f958SSadaf Ebrahimi //   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)
145*6467f958SSadaf Ebrahimi //   mem_level must be between [1, 9] (it's checked but ignored by miniz.c)
146*6467f958SSadaf Ebrahimi int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
147*6467f958SSadaf Ebrahimi 
148*6467f958SSadaf Ebrahimi // Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2().
149*6467f958SSadaf Ebrahimi int mz_deflateReset(mz_streamp pStream);
150*6467f958SSadaf Ebrahimi 
151*6467f958SSadaf Ebrahimi // mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
152*6467f958SSadaf Ebrahimi // Parameters:
153*6467f958SSadaf Ebrahimi //   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.
154*6467f958SSadaf Ebrahimi //   flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH.
155*6467f958SSadaf Ebrahimi // Return values:
156*6467f958SSadaf Ebrahimi //   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).
157*6467f958SSadaf Ebrahimi //   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.
158*6467f958SSadaf Ebrahimi //   MZ_STREAM_ERROR if the stream is bogus.
159*6467f958SSadaf Ebrahimi //   MZ_PARAM_ERROR if one of the parameters is invalid.
160*6467f958SSadaf Ebrahimi //   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.)
161*6467f958SSadaf Ebrahimi int mz_deflate(mz_streamp pStream, int flush);
162*6467f958SSadaf Ebrahimi 
163*6467f958SSadaf Ebrahimi // mz_deflateEnd() deinitializes a compressor:
164*6467f958SSadaf Ebrahimi // Return values:
165*6467f958SSadaf Ebrahimi //  MZ_OK on success.
166*6467f958SSadaf Ebrahimi //  MZ_STREAM_ERROR if the stream is bogus.
167*6467f958SSadaf Ebrahimi int mz_deflateEnd(mz_streamp pStream);
168*6467f958SSadaf Ebrahimi 
169*6467f958SSadaf Ebrahimi // 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.
170*6467f958SSadaf Ebrahimi mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
171*6467f958SSadaf Ebrahimi 
172*6467f958SSadaf Ebrahimi // Single-call compression functions mz_compress() and mz_compress2():
173*6467f958SSadaf Ebrahimi // Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure.
174*6467f958SSadaf Ebrahimi int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
175*6467f958SSadaf Ebrahimi int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level);
176*6467f958SSadaf Ebrahimi 
177*6467f958SSadaf Ebrahimi // mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress().
178*6467f958SSadaf Ebrahimi mz_ulong mz_compressBound(mz_ulong source_len);
179*6467f958SSadaf Ebrahimi 
180*6467f958SSadaf Ebrahimi // Initializes a decompressor.
181*6467f958SSadaf Ebrahimi int mz_inflateInit(mz_streamp pStream);
182*6467f958SSadaf Ebrahimi 
183*6467f958SSadaf Ebrahimi // 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:
184*6467f958SSadaf Ebrahimi // window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate).
185*6467f958SSadaf Ebrahimi int mz_inflateInit2(mz_streamp pStream, int window_bits);
186*6467f958SSadaf Ebrahimi 
187*6467f958SSadaf Ebrahimi // 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.
188*6467f958SSadaf Ebrahimi // Parameters:
189*6467f958SSadaf Ebrahimi //   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.
190*6467f958SSadaf Ebrahimi //   flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH.
191*6467f958SSadaf Ebrahimi //   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).
192*6467f958SSadaf Ebrahimi //   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.
193*6467f958SSadaf Ebrahimi // Return values:
194*6467f958SSadaf Ebrahimi //   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.
195*6467f958SSadaf Ebrahimi //   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.
196*6467f958SSadaf Ebrahimi //   MZ_STREAM_ERROR if the stream is bogus.
197*6467f958SSadaf Ebrahimi //   MZ_DATA_ERROR if the deflate stream is invalid.
198*6467f958SSadaf Ebrahimi //   MZ_PARAM_ERROR if one of the parameters is invalid.
199*6467f958SSadaf Ebrahimi //   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
200*6467f958SSadaf Ebrahimi //   with more input data, or with more room in the output buffer (except when using single call decompression, described above).
201*6467f958SSadaf Ebrahimi int mz_inflate(mz_streamp pStream, int flush);
202*6467f958SSadaf Ebrahimi 
203*6467f958SSadaf Ebrahimi // Deinitializes a decompressor.
204*6467f958SSadaf Ebrahimi int mz_inflateEnd(mz_streamp pStream);
205*6467f958SSadaf Ebrahimi 
206*6467f958SSadaf Ebrahimi // Single-call decompression.
207*6467f958SSadaf Ebrahimi // Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure.
208*6467f958SSadaf Ebrahimi int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
209*6467f958SSadaf Ebrahimi 
210*6467f958SSadaf Ebrahimi // Returns a string description of the specified error code, or NULL if the error code is invalid.
211*6467f958SSadaf Ebrahimi const char *mz_error(int err);
212*6467f958SSadaf Ebrahimi 
213*6467f958SSadaf Ebrahimi // 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.
214*6467f958SSadaf Ebrahimi // Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project.
215*6467f958SSadaf Ebrahimi #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
216*6467f958SSadaf Ebrahimi   typedef unsigned char Byte;
217*6467f958SSadaf Ebrahimi   typedef unsigned int uInt;
218*6467f958SSadaf Ebrahimi   typedef mz_ulong uLong;
219*6467f958SSadaf Ebrahimi   typedef Byte Bytef;
220*6467f958SSadaf Ebrahimi   typedef uInt uIntf;
221*6467f958SSadaf Ebrahimi   typedef char charf;
222*6467f958SSadaf Ebrahimi   typedef int intf;
223*6467f958SSadaf Ebrahimi   typedef void *voidpf;
224*6467f958SSadaf Ebrahimi   typedef uLong uLongf;
225*6467f958SSadaf Ebrahimi   typedef void *voidp;
226*6467f958SSadaf Ebrahimi   typedef void *const voidpc;
227*6467f958SSadaf Ebrahimi   #define Z_NULL                0
228*6467f958SSadaf Ebrahimi   #define Z_NO_FLUSH            MZ_NO_FLUSH
229*6467f958SSadaf Ebrahimi   #define Z_PARTIAL_FLUSH       MZ_PARTIAL_FLUSH
230*6467f958SSadaf Ebrahimi   #define Z_SYNC_FLUSH          MZ_SYNC_FLUSH
231*6467f958SSadaf Ebrahimi   #define Z_FULL_FLUSH          MZ_FULL_FLUSH
232*6467f958SSadaf Ebrahimi   #define Z_FINISH              MZ_FINISH
233*6467f958SSadaf Ebrahimi   #define Z_BLOCK               MZ_BLOCK
234*6467f958SSadaf Ebrahimi   #define Z_OK                  MZ_OK
235*6467f958SSadaf Ebrahimi   #define Z_STREAM_END          MZ_STREAM_END
236*6467f958SSadaf Ebrahimi   #define Z_NEED_DICT           MZ_NEED_DICT
237*6467f958SSadaf Ebrahimi   #define Z_ERRNO               MZ_ERRNO
238*6467f958SSadaf Ebrahimi   #define Z_STREAM_ERROR        MZ_STREAM_ERROR
239*6467f958SSadaf Ebrahimi   #define Z_DATA_ERROR          MZ_DATA_ERROR
240*6467f958SSadaf Ebrahimi   #define Z_MEM_ERROR           MZ_MEM_ERROR
241*6467f958SSadaf Ebrahimi   #define Z_BUF_ERROR           MZ_BUF_ERROR
242*6467f958SSadaf Ebrahimi   #define Z_VERSION_ERROR       MZ_VERSION_ERROR
243*6467f958SSadaf Ebrahimi   #define Z_PARAM_ERROR         MZ_PARAM_ERROR
244*6467f958SSadaf Ebrahimi   #define Z_NO_COMPRESSION      MZ_NO_COMPRESSION
245*6467f958SSadaf Ebrahimi   #define Z_BEST_SPEED          MZ_BEST_SPEED
246*6467f958SSadaf Ebrahimi   #define Z_BEST_COMPRESSION    MZ_BEST_COMPRESSION
247*6467f958SSadaf Ebrahimi   #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
248*6467f958SSadaf Ebrahimi   #define Z_DEFAULT_STRATEGY    MZ_DEFAULT_STRATEGY
249*6467f958SSadaf Ebrahimi   #define Z_FILTERED            MZ_FILTERED
250*6467f958SSadaf Ebrahimi   #define Z_HUFFMAN_ONLY        MZ_HUFFMAN_ONLY
251*6467f958SSadaf Ebrahimi   #define Z_RLE                 MZ_RLE
252*6467f958SSadaf Ebrahimi   #define Z_FIXED               MZ_FIXED
253*6467f958SSadaf Ebrahimi   #define Z_DEFLATED            MZ_DEFLATED
254*6467f958SSadaf Ebrahimi   #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
255*6467f958SSadaf Ebrahimi   #define alloc_func            mz_alloc_func
256*6467f958SSadaf Ebrahimi   #define free_func             mz_free_func
257*6467f958SSadaf Ebrahimi   #define internal_state        mz_internal_state
258*6467f958SSadaf Ebrahimi   #define z_stream              mz_stream
259*6467f958SSadaf Ebrahimi   #define deflateInit           mz_deflateInit
260*6467f958SSadaf Ebrahimi   #define deflateInit2          mz_deflateInit2
261*6467f958SSadaf Ebrahimi   #define deflateReset          mz_deflateReset
262*6467f958SSadaf Ebrahimi   #define deflate               mz_deflate
263*6467f958SSadaf Ebrahimi   #define deflateEnd            mz_deflateEnd
264*6467f958SSadaf Ebrahimi   #define deflateBound          mz_deflateBound
265*6467f958SSadaf Ebrahimi   #define compress              mz_compress
266*6467f958SSadaf Ebrahimi   #define compress2             mz_compress2
267*6467f958SSadaf Ebrahimi   #define compressBound         mz_compressBound
268*6467f958SSadaf Ebrahimi   #define inflateInit           mz_inflateInit
269*6467f958SSadaf Ebrahimi   #define inflateInit2          mz_inflateInit2
270*6467f958SSadaf Ebrahimi   #define inflate               mz_inflate
271*6467f958SSadaf Ebrahimi   #define inflateEnd            mz_inflateEnd
272*6467f958SSadaf Ebrahimi   #define uncompress            mz_uncompress
273*6467f958SSadaf Ebrahimi   #define crc32                 mz_crc32
274*6467f958SSadaf Ebrahimi   #define adler32               mz_adler32
275*6467f958SSadaf Ebrahimi   #define MAX_WBITS             15
276*6467f958SSadaf Ebrahimi   #define MAX_MEM_LEVEL         9
277*6467f958SSadaf Ebrahimi   #define zError                mz_error
278*6467f958SSadaf Ebrahimi   #define ZLIB_VERSION          MZ_VERSION
279*6467f958SSadaf Ebrahimi   #define ZLIB_VERNUM           MZ_VERNUM
280*6467f958SSadaf Ebrahimi   #define ZLIB_VER_MAJOR        MZ_VER_MAJOR
281*6467f958SSadaf Ebrahimi   #define ZLIB_VER_MINOR        MZ_VER_MINOR
282*6467f958SSadaf Ebrahimi   #define ZLIB_VER_REVISION     MZ_VER_REVISION
283*6467f958SSadaf Ebrahimi   #define ZLIB_VER_SUBREVISION  MZ_VER_SUBREVISION
284*6467f958SSadaf Ebrahimi   #define zlibVersion           mz_version
285*6467f958SSadaf Ebrahimi   #define zlib_version          mz_version()
286*6467f958SSadaf Ebrahimi #endif // #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
287*6467f958SSadaf Ebrahimi 
288*6467f958SSadaf Ebrahimi #endif // MINIZ_NO_ZLIB_APIS
289*6467f958SSadaf Ebrahimi 
290*6467f958SSadaf Ebrahimi // ------------------- Types and macros
291*6467f958SSadaf Ebrahimi 
292*6467f958SSadaf Ebrahimi typedef unsigned char mz_uint8;
293*6467f958SSadaf Ebrahimi typedef signed short mz_int16;
294*6467f958SSadaf Ebrahimi typedef unsigned short mz_uint16;
295*6467f958SSadaf Ebrahimi typedef unsigned int mz_uint32;
296*6467f958SSadaf Ebrahimi typedef unsigned int mz_uint;
297*6467f958SSadaf Ebrahimi typedef long long mz_int64;
298*6467f958SSadaf Ebrahimi typedef unsigned long long mz_uint64;
299*6467f958SSadaf Ebrahimi typedef int mz_bool;
300*6467f958SSadaf Ebrahimi 
301*6467f958SSadaf Ebrahimi #define MZ_FALSE (0)
302*6467f958SSadaf Ebrahimi #define MZ_TRUE (1)
303*6467f958SSadaf Ebrahimi 
304*6467f958SSadaf Ebrahimi // An attempt to work around MSVC's spammy "warning C4127: conditional expression is constant" message.
305*6467f958SSadaf Ebrahimi #ifdef _MSC_VER
306*6467f958SSadaf Ebrahimi    #define MZ_MACRO_END while (0, 0)
307*6467f958SSadaf Ebrahimi #else
308*6467f958SSadaf Ebrahimi    #define MZ_MACRO_END while (0)
309*6467f958SSadaf Ebrahimi #endif
310*6467f958SSadaf Ebrahimi 
311*6467f958SSadaf Ebrahimi // ------------------- ZIP archive reading/writing
312*6467f958SSadaf Ebrahimi 
313*6467f958SSadaf Ebrahimi #ifndef MINIZ_NO_ARCHIVE_APIS
314*6467f958SSadaf Ebrahimi 
315*6467f958SSadaf Ebrahimi enum
316*6467f958SSadaf Ebrahimi {
317*6467f958SSadaf Ebrahimi   MZ_ZIP_MAX_IO_BUF_SIZE = 64*1024,
318*6467f958SSadaf Ebrahimi   MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 260,
319*6467f958SSadaf Ebrahimi   MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 256
320*6467f958SSadaf Ebrahimi };
321*6467f958SSadaf Ebrahimi 
322*6467f958SSadaf Ebrahimi typedef struct
323*6467f958SSadaf Ebrahimi {
324*6467f958SSadaf Ebrahimi   mz_uint32 m_file_index;
325*6467f958SSadaf Ebrahimi   mz_uint32 m_central_dir_ofs;
326*6467f958SSadaf Ebrahimi   mz_uint16 m_version_made_by;
327*6467f958SSadaf Ebrahimi   mz_uint16 m_version_needed;
328*6467f958SSadaf Ebrahimi   mz_uint16 m_bit_flag;
329*6467f958SSadaf Ebrahimi   mz_uint16 m_method;
330*6467f958SSadaf Ebrahimi #ifndef MINIZ_NO_TIME
331*6467f958SSadaf Ebrahimi   time_t m_time;
332*6467f958SSadaf Ebrahimi #endif
333*6467f958SSadaf Ebrahimi   mz_uint32 m_crc32;
334*6467f958SSadaf Ebrahimi   mz_uint64 m_comp_size;
335*6467f958SSadaf Ebrahimi   mz_uint64 m_uncomp_size;
336*6467f958SSadaf Ebrahimi   mz_uint16 m_internal_attr;
337*6467f958SSadaf Ebrahimi   mz_uint32 m_external_attr;
338*6467f958SSadaf Ebrahimi   mz_uint64 m_local_header_ofs;
339*6467f958SSadaf Ebrahimi   mz_uint32 m_comment_size;
340*6467f958SSadaf Ebrahimi   char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
341*6467f958SSadaf Ebrahimi   char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
342*6467f958SSadaf Ebrahimi } mz_zip_archive_file_stat;
343*6467f958SSadaf Ebrahimi 
344*6467f958SSadaf Ebrahimi typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
345*6467f958SSadaf Ebrahimi typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
346*6467f958SSadaf Ebrahimi 
347*6467f958SSadaf Ebrahimi struct mz_zip_internal_state_tag;
348*6467f958SSadaf Ebrahimi typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
349*6467f958SSadaf Ebrahimi 
350*6467f958SSadaf Ebrahimi typedef enum
351*6467f958SSadaf Ebrahimi {
352*6467f958SSadaf Ebrahimi   MZ_ZIP_MODE_INVALID = 0,
353*6467f958SSadaf Ebrahimi   MZ_ZIP_MODE_READING = 1,
354*6467f958SSadaf Ebrahimi   MZ_ZIP_MODE_WRITING = 2,
355*6467f958SSadaf Ebrahimi   MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
356*6467f958SSadaf Ebrahimi } mz_zip_mode;
357*6467f958SSadaf Ebrahimi 
358*6467f958SSadaf Ebrahimi typedef struct mz_zip_archive_tag
359*6467f958SSadaf Ebrahimi {
360*6467f958SSadaf Ebrahimi   mz_uint64 m_archive_size;
361*6467f958SSadaf Ebrahimi   mz_uint64 m_central_directory_file_ofs;
362*6467f958SSadaf Ebrahimi   mz_uint m_total_files;
363*6467f958SSadaf Ebrahimi   mz_zip_mode m_zip_mode;
364*6467f958SSadaf Ebrahimi 
365*6467f958SSadaf Ebrahimi   mz_uint m_file_offset_alignment;
366*6467f958SSadaf Ebrahimi 
367*6467f958SSadaf Ebrahimi   mz_alloc_func m_pAlloc;
368*6467f958SSadaf Ebrahimi   mz_free_func m_pFree;
369*6467f958SSadaf Ebrahimi   mz_realloc_func m_pRealloc;
370*6467f958SSadaf Ebrahimi   void *m_pAlloc_opaque;
371*6467f958SSadaf Ebrahimi 
372*6467f958SSadaf Ebrahimi   mz_file_read_func m_pRead;
373*6467f958SSadaf Ebrahimi   mz_file_write_func m_pWrite;
374*6467f958SSadaf Ebrahimi   void *m_pIO_opaque;
375*6467f958SSadaf Ebrahimi 
376*6467f958SSadaf Ebrahimi   mz_zip_internal_state *m_pState;
377*6467f958SSadaf Ebrahimi 
378*6467f958SSadaf Ebrahimi } mz_zip_archive;
379*6467f958SSadaf Ebrahimi 
380*6467f958SSadaf Ebrahimi typedef enum
381*6467f958SSadaf Ebrahimi {
382*6467f958SSadaf Ebrahimi   MZ_ZIP_FLAG_CASE_SENSITIVE                = 0x0100,
383*6467f958SSadaf Ebrahimi   MZ_ZIP_FLAG_IGNORE_PATH                   = 0x0200,
384*6467f958SSadaf Ebrahimi   MZ_ZIP_FLAG_COMPRESSED_DATA               = 0x0400,
385*6467f958SSadaf Ebrahimi   MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800
386*6467f958SSadaf Ebrahimi } mz_zip_flags;
387*6467f958SSadaf Ebrahimi 
388*6467f958SSadaf Ebrahimi // ZIP archive reading
389*6467f958SSadaf Ebrahimi 
390*6467f958SSadaf Ebrahimi // Inits a ZIP archive reader.
391*6467f958SSadaf Ebrahimi // These functions read and validate the archive's central directory.
392*6467f958SSadaf Ebrahimi mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint32 flags);
393*6467f958SSadaf Ebrahimi mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint32 flags);
394*6467f958SSadaf Ebrahimi 
395*6467f958SSadaf Ebrahimi #ifndef MINIZ_NO_STDIO
396*6467f958SSadaf Ebrahimi mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
397*6467f958SSadaf Ebrahimi #endif
398*6467f958SSadaf Ebrahimi 
399*6467f958SSadaf Ebrahimi // Returns the total number of files in the archive.
400*6467f958SSadaf Ebrahimi mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
401*6467f958SSadaf Ebrahimi 
402*6467f958SSadaf Ebrahimi // Returns detailed information about an archive file entry.
403*6467f958SSadaf Ebrahimi mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
404*6467f958SSadaf Ebrahimi 
405*6467f958SSadaf Ebrahimi // Determines if an archive file entry is a directory entry.
406*6467f958SSadaf Ebrahimi mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
407*6467f958SSadaf Ebrahimi mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
408*6467f958SSadaf Ebrahimi 
409*6467f958SSadaf Ebrahimi // Retrieves the filename of an archive file entry.
410*6467f958SSadaf Ebrahimi // 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.
411*6467f958SSadaf Ebrahimi mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
412*6467f958SSadaf Ebrahimi 
413*6467f958SSadaf Ebrahimi // Attempts to locates a file in the archive's central directory.
414*6467f958SSadaf Ebrahimi // Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH
415*6467f958SSadaf Ebrahimi // Returns -1 if the file cannot be found.
416*6467f958SSadaf Ebrahimi int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
417*6467f958SSadaf Ebrahimi 
418*6467f958SSadaf Ebrahimi // Extracts a archive file to a memory buffer using no memory allocation.
419*6467f958SSadaf Ebrahimi 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);
420*6467f958SSadaf Ebrahimi 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);
421*6467f958SSadaf Ebrahimi 
422*6467f958SSadaf Ebrahimi // Extracts a archive file to a memory buffer.
423*6467f958SSadaf Ebrahimi 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);
424*6467f958SSadaf Ebrahimi 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);
425*6467f958SSadaf Ebrahimi 
426*6467f958SSadaf Ebrahimi // Extracts a archive file to a dynamically allocated heap buffer.
427*6467f958SSadaf Ebrahimi void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
428*6467f958SSadaf Ebrahimi void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
429*6467f958SSadaf Ebrahimi 
430*6467f958SSadaf Ebrahimi // Extracts a archive file using a callback function to output the file's data.
431*6467f958SSadaf Ebrahimi 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);
432*6467f958SSadaf Ebrahimi 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);
433*6467f958SSadaf Ebrahimi 
434*6467f958SSadaf Ebrahimi #ifndef MINIZ_NO_STDIO
435*6467f958SSadaf Ebrahimi // Extracts a archive file to a disk file and sets its last accessed and modified times.
436*6467f958SSadaf Ebrahimi // This function only extracts files, not archive directory records.
437*6467f958SSadaf Ebrahimi mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
438*6467f958SSadaf Ebrahimi mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
439*6467f958SSadaf Ebrahimi #endif
440*6467f958SSadaf Ebrahimi 
441*6467f958SSadaf Ebrahimi // Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used.
442*6467f958SSadaf Ebrahimi mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
443*6467f958SSadaf Ebrahimi 
444*6467f958SSadaf Ebrahimi // ZIP archive writing
445*6467f958SSadaf Ebrahimi 
446*6467f958SSadaf Ebrahimi #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
447*6467f958SSadaf Ebrahimi 
448*6467f958SSadaf Ebrahimi // Inits a ZIP archive writer.
449*6467f958SSadaf Ebrahimi mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
450*6467f958SSadaf Ebrahimi mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
451*6467f958SSadaf Ebrahimi 
452*6467f958SSadaf Ebrahimi #ifndef MINIZ_NO_STDIO
453*6467f958SSadaf Ebrahimi mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
454*6467f958SSadaf Ebrahimi #endif
455*6467f958SSadaf Ebrahimi 
456*6467f958SSadaf Ebrahimi // Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive.
457*6467f958SSadaf Ebrahimi // 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.
458*6467f958SSadaf Ebrahimi // 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).
459*6467f958SSadaf Ebrahimi // Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL.
460*6467f958SSadaf Ebrahimi // Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before
461*6467f958SSadaf Ebrahimi // the archive is finalized the file's central directory will be hosed.
462*6467f958SSadaf Ebrahimi mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
463*6467f958SSadaf Ebrahimi 
464*6467f958SSadaf Ebrahimi // Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive.
465*6467f958SSadaf Ebrahimi // To add a directory entry, call this method with an archive name ending in a forwardslash with empty buffer.
466*6467f958SSadaf Ebrahimi // 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.
467*6467f958SSadaf Ebrahimi 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);
468*6467f958SSadaf Ebrahimi 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);
469*6467f958SSadaf Ebrahimi 
470*6467f958SSadaf Ebrahimi #ifndef MINIZ_NO_STDIO
471*6467f958SSadaf Ebrahimi // Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive.
472*6467f958SSadaf Ebrahimi // 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.
473*6467f958SSadaf Ebrahimi 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);
474*6467f958SSadaf Ebrahimi #endif
475*6467f958SSadaf Ebrahimi 
476*6467f958SSadaf Ebrahimi // Adds a file to an archive by fully cloning the data from another archive.
477*6467f958SSadaf Ebrahimi // This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data, and comment fields.
478*6467f958SSadaf Ebrahimi mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint file_index);
479*6467f958SSadaf Ebrahimi 
480*6467f958SSadaf Ebrahimi // Finalizes the archive by writing the central directory records followed by the end of central directory record.
481*6467f958SSadaf Ebrahimi // After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end().
482*6467f958SSadaf Ebrahimi // An archive must be manually finalized by calling this function for it to be valid.
483*6467f958SSadaf Ebrahimi mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
484*6467f958SSadaf Ebrahimi mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **pBuf, size_t *pSize);
485*6467f958SSadaf Ebrahimi 
486*6467f958SSadaf Ebrahimi // Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used.
487*6467f958SSadaf Ebrahimi // Note for the archive to be valid, it must have been finalized before ending.
488*6467f958SSadaf Ebrahimi mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
489*6467f958SSadaf Ebrahimi 
490*6467f958SSadaf Ebrahimi // Misc. high-level helper functions:
491*6467f958SSadaf Ebrahimi 
492*6467f958SSadaf Ebrahimi // mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive.
493*6467f958SSadaf Ebrahimi // 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.
494*6467f958SSadaf Ebrahimi 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);
495*6467f958SSadaf Ebrahimi 
496*6467f958SSadaf Ebrahimi // Reads a single file from an archive into a heap block.
497*6467f958SSadaf Ebrahimi // Returns NULL on failure.
498*6467f958SSadaf Ebrahimi void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint zip_flags);
499*6467f958SSadaf Ebrahimi 
500*6467f958SSadaf Ebrahimi #endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
501*6467f958SSadaf Ebrahimi 
502*6467f958SSadaf Ebrahimi #endif // #ifndef MINIZ_NO_ARCHIVE_APIS
503*6467f958SSadaf Ebrahimi 
504*6467f958SSadaf Ebrahimi // ------------------- Low-level Decompression API Definitions
505*6467f958SSadaf Ebrahimi 
506*6467f958SSadaf Ebrahimi // Decompression flags used by tinfl_decompress().
507*6467f958SSadaf Ebrahimi // 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.
508*6467f958SSadaf Ebrahimi // 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.
509*6467f958SSadaf Ebrahimi // 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).
510*6467f958SSadaf Ebrahimi // TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes.
511*6467f958SSadaf Ebrahimi enum
512*6467f958SSadaf Ebrahimi {
513*6467f958SSadaf Ebrahimi   TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
514*6467f958SSadaf Ebrahimi   TINFL_FLAG_HAS_MORE_INPUT = 2,
515*6467f958SSadaf Ebrahimi   TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
516*6467f958SSadaf Ebrahimi   TINFL_FLAG_COMPUTE_ADLER32 = 8
517*6467f958SSadaf Ebrahimi };
518*6467f958SSadaf Ebrahimi 
519*6467f958SSadaf Ebrahimi // High level decompression functions:
520*6467f958SSadaf Ebrahimi // tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc().
521*6467f958SSadaf Ebrahimi // On entry:
522*6467f958SSadaf Ebrahimi //  pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress.
523*6467f958SSadaf Ebrahimi // On return:
524*6467f958SSadaf Ebrahimi //  Function returns a pointer to the decompressed data, or NULL on failure.
525*6467f958SSadaf Ebrahimi //  *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data.
526*6467f958SSadaf Ebrahimi //  The caller must call mz_free() on the returned block when it's no longer needed.
527*6467f958SSadaf Ebrahimi void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
528*6467f958SSadaf Ebrahimi 
529*6467f958SSadaf Ebrahimi // tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory.
530*6467f958SSadaf Ebrahimi // Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success.
531*6467f958SSadaf Ebrahimi #define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
532*6467f958SSadaf Ebrahimi 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);
533*6467f958SSadaf Ebrahimi 
534*6467f958SSadaf Ebrahimi // 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.
535*6467f958SSadaf Ebrahimi // Returns 1 on success or 0 on failure.
536*6467f958SSadaf Ebrahimi typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
537*6467f958SSadaf Ebrahimi 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);
538*6467f958SSadaf Ebrahimi 
539*6467f958SSadaf Ebrahimi struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor;
540*6467f958SSadaf Ebrahimi 
541*6467f958SSadaf Ebrahimi // Max size of LZ dictionary.
542*6467f958SSadaf Ebrahimi #define TINFL_LZ_DICT_SIZE 32768
543*6467f958SSadaf Ebrahimi 
544*6467f958SSadaf Ebrahimi // Return status.
545*6467f958SSadaf Ebrahimi typedef enum
546*6467f958SSadaf Ebrahimi {
547*6467f958SSadaf Ebrahimi   TINFL_STATUS_BAD_PARAM = -3,
548*6467f958SSadaf Ebrahimi   TINFL_STATUS_ADLER32_MISMATCH = -2,
549*6467f958SSadaf Ebrahimi   TINFL_STATUS_FAILED = -1,
550*6467f958SSadaf Ebrahimi   TINFL_STATUS_DONE = 0,
551*6467f958SSadaf Ebrahimi   TINFL_STATUS_NEEDS_MORE_INPUT = 1,
552*6467f958SSadaf Ebrahimi   TINFL_STATUS_HAS_MORE_OUTPUT = 2
553*6467f958SSadaf Ebrahimi } tinfl_status;
554*6467f958SSadaf Ebrahimi 
555*6467f958SSadaf Ebrahimi // Initializes the decompressor to its initial state.
556*6467f958SSadaf Ebrahimi #define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END
557*6467f958SSadaf Ebrahimi #define tinfl_get_adler32(r) (r)->m_check_adler32
558*6467f958SSadaf Ebrahimi 
559*6467f958SSadaf Ebrahimi // 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.
560*6467f958SSadaf Ebrahimi // 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.
561*6467f958SSadaf Ebrahimi 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);
562*6467f958SSadaf Ebrahimi 
563*6467f958SSadaf Ebrahimi // Internal/private bits follow.
564*6467f958SSadaf Ebrahimi enum
565*6467f958SSadaf Ebrahimi {
566*6467f958SSadaf Ebrahimi   TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19,
567*6467f958SSadaf Ebrahimi   TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
568*6467f958SSadaf Ebrahimi };
569*6467f958SSadaf Ebrahimi 
570*6467f958SSadaf Ebrahimi typedef struct
571*6467f958SSadaf Ebrahimi {
572*6467f958SSadaf Ebrahimi   mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
573*6467f958SSadaf Ebrahimi   mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
574*6467f958SSadaf Ebrahimi } tinfl_huff_table;
575*6467f958SSadaf Ebrahimi 
576*6467f958SSadaf Ebrahimi #if MINIZ_HAS_64BIT_REGISTERS
577*6467f958SSadaf Ebrahimi   #define TINFL_USE_64BIT_BITBUF 1
578*6467f958SSadaf Ebrahimi #endif
579*6467f958SSadaf Ebrahimi 
580*6467f958SSadaf Ebrahimi #if TINFL_USE_64BIT_BITBUF
581*6467f958SSadaf Ebrahimi   typedef mz_uint64 tinfl_bit_buf_t;
582*6467f958SSadaf Ebrahimi   #define TINFL_BITBUF_SIZE (64)
583*6467f958SSadaf Ebrahimi #else
584*6467f958SSadaf Ebrahimi   typedef mz_uint32 tinfl_bit_buf_t;
585*6467f958SSadaf Ebrahimi   #define TINFL_BITBUF_SIZE (32)
586*6467f958SSadaf Ebrahimi #endif
587*6467f958SSadaf Ebrahimi 
588*6467f958SSadaf Ebrahimi struct tinfl_decompressor_tag
589*6467f958SSadaf Ebrahimi {
590*6467f958SSadaf Ebrahimi   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];
591*6467f958SSadaf Ebrahimi   tinfl_bit_buf_t m_bit_buf;
592*6467f958SSadaf Ebrahimi   size_t m_dist_from_out_buf_start;
593*6467f958SSadaf Ebrahimi   tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
594*6467f958SSadaf Ebrahimi   mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
595*6467f958SSadaf Ebrahimi };
596*6467f958SSadaf Ebrahimi 
597*6467f958SSadaf Ebrahimi // ------------------- Low-level Compression API Definitions
598*6467f958SSadaf Ebrahimi 
599*6467f958SSadaf Ebrahimi // Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently).
600*6467f958SSadaf Ebrahimi #define TDEFL_LESS_MEMORY 0
601*6467f958SSadaf Ebrahimi 
602*6467f958SSadaf Ebrahimi // tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search):
603*6467f958SSadaf Ebrahimi // 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).
604*6467f958SSadaf Ebrahimi enum
605*6467f958SSadaf Ebrahimi {
606*6467f958SSadaf Ebrahimi   TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF
607*6467f958SSadaf Ebrahimi };
608*6467f958SSadaf Ebrahimi 
609*6467f958SSadaf Ebrahimi // 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.
610*6467f958SSadaf Ebrahimi // TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers).
611*6467f958SSadaf Ebrahimi // TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing.
612*6467f958SSadaf Ebrahimi // 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).
613*6467f958SSadaf Ebrahimi // TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1)
614*6467f958SSadaf Ebrahimi // TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled.
615*6467f958SSadaf Ebrahimi // TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables.
616*6467f958SSadaf Ebrahimi // TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks.
617*6467f958SSadaf Ebrahimi // The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK).
618*6467f958SSadaf Ebrahimi enum
619*6467f958SSadaf Ebrahimi {
620*6467f958SSadaf Ebrahimi   TDEFL_WRITE_ZLIB_HEADER             = 0x01000,
621*6467f958SSadaf Ebrahimi   TDEFL_COMPUTE_ADLER32               = 0x02000,
622*6467f958SSadaf Ebrahimi   TDEFL_GREEDY_PARSING_FLAG           = 0x04000,
623*6467f958SSadaf Ebrahimi   TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
624*6467f958SSadaf Ebrahimi   TDEFL_RLE_MATCHES                   = 0x10000,
625*6467f958SSadaf Ebrahimi   TDEFL_FILTER_MATCHES                = 0x20000,
626*6467f958SSadaf Ebrahimi   TDEFL_FORCE_ALL_STATIC_BLOCKS       = 0x40000,
627*6467f958SSadaf Ebrahimi   TDEFL_FORCE_ALL_RAW_BLOCKS          = 0x80000
628*6467f958SSadaf Ebrahimi };
629*6467f958SSadaf Ebrahimi 
630*6467f958SSadaf Ebrahimi // High level compression functions:
631*6467f958SSadaf Ebrahimi // tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc().
632*6467f958SSadaf Ebrahimi // On entry:
633*6467f958SSadaf Ebrahimi //  pSrc_buf, src_buf_len: Pointer and size of source block to compress.
634*6467f958SSadaf Ebrahimi //  flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression.
635*6467f958SSadaf Ebrahimi // On return:
636*6467f958SSadaf Ebrahimi //  Function returns a pointer to the compressed data, or NULL on failure.
637*6467f958SSadaf Ebrahimi //  *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data.
638*6467f958SSadaf Ebrahimi //  The caller must free() the returned block when it's no longer needed.
639*6467f958SSadaf Ebrahimi void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
640*6467f958SSadaf Ebrahimi 
641*6467f958SSadaf Ebrahimi // tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory.
642*6467f958SSadaf Ebrahimi // Returns 0 on failure.
643*6467f958SSadaf Ebrahimi 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);
644*6467f958SSadaf Ebrahimi 
645*6467f958SSadaf Ebrahimi // Compresses an image to a compressed PNG file in memory.
646*6467f958SSadaf Ebrahimi // On entry:
647*6467f958SSadaf Ebrahimi //  pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4.
648*6467f958SSadaf Ebrahimi //  The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory.
649*6467f958SSadaf Ebrahimi //  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
650*6467f958SSadaf Ebrahimi //  If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps).
651*6467f958SSadaf Ebrahimi // On return:
652*6467f958SSadaf Ebrahimi //  Function returns a pointer to the compressed data, or NULL on failure.
653*6467f958SSadaf Ebrahimi //  *pLen_out will be set to the size of the PNG image file.
654*6467f958SSadaf Ebrahimi //  The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
655*6467f958SSadaf Ebrahimi 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);
656*6467f958SSadaf Ebrahimi void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
657*6467f958SSadaf Ebrahimi 
658*6467f958SSadaf Ebrahimi // Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
659*6467f958SSadaf Ebrahimi typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
660*6467f958SSadaf Ebrahimi 
661*6467f958SSadaf Ebrahimi // tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally.
662*6467f958SSadaf Ebrahimi 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);
663*6467f958SSadaf Ebrahimi 
664*6467f958SSadaf Ebrahimi enum { TDEFL_MAX_HUFF_TABLES = 3, TDEFL_MAX_HUFF_SYMBOLS_0 = 288, TDEFL_MAX_HUFF_SYMBOLS_1 = 32, TDEFL_MAX_HUFF_SYMBOLS_2 = 19, TDEFL_LZ_DICT_SIZE = 32768, TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, TDEFL_MIN_MATCH_LEN = 3, TDEFL_MAX_MATCH_LEN = 258 };
665*6467f958SSadaf Ebrahimi 
666*6467f958SSadaf Ebrahimi // TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes).
667*6467f958SSadaf Ebrahimi #if TDEFL_LESS_MEMORY
668*6467f958SSadaf Ebrahimi enum { TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 12, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
669*6467f958SSadaf Ebrahimi #else
670*6467f958SSadaf Ebrahimi enum { TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 15, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
671*6467f958SSadaf Ebrahimi #endif
672*6467f958SSadaf Ebrahimi 
673*6467f958SSadaf Ebrahimi // 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.
674*6467f958SSadaf Ebrahimi typedef enum
675*6467f958SSadaf Ebrahimi {
676*6467f958SSadaf Ebrahimi   TDEFL_STATUS_BAD_PARAM = -2,
677*6467f958SSadaf Ebrahimi   TDEFL_STATUS_PUT_BUF_FAILED = -1,
678*6467f958SSadaf Ebrahimi   TDEFL_STATUS_OKAY = 0,
679*6467f958SSadaf Ebrahimi   TDEFL_STATUS_DONE = 1,
680*6467f958SSadaf Ebrahimi } tdefl_status;
681*6467f958SSadaf Ebrahimi 
682*6467f958SSadaf Ebrahimi // Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums
683*6467f958SSadaf Ebrahimi typedef enum
684*6467f958SSadaf Ebrahimi {
685*6467f958SSadaf Ebrahimi   TDEFL_NO_FLUSH = 0,
686*6467f958SSadaf Ebrahimi   TDEFL_SYNC_FLUSH = 2,
687*6467f958SSadaf Ebrahimi   TDEFL_FULL_FLUSH = 3,
688*6467f958SSadaf Ebrahimi   TDEFL_FINISH = 4
689*6467f958SSadaf Ebrahimi } tdefl_flush;
690*6467f958SSadaf Ebrahimi 
691*6467f958SSadaf Ebrahimi // tdefl's compression state structure.
692*6467f958SSadaf Ebrahimi typedef struct
693*6467f958SSadaf Ebrahimi {
694*6467f958SSadaf Ebrahimi   tdefl_put_buf_func_ptr m_pPut_buf_func;
695*6467f958SSadaf Ebrahimi   void *m_pPut_buf_user;
696*6467f958SSadaf Ebrahimi   mz_uint m_flags, m_max_probes[2];
697*6467f958SSadaf Ebrahimi   int m_greedy_parsing;
698*6467f958SSadaf Ebrahimi   mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size;
699*6467f958SSadaf Ebrahimi   mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end;
700*6467f958SSadaf Ebrahimi   mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer;
701*6467f958SSadaf Ebrahimi   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;
702*6467f958SSadaf Ebrahimi   tdefl_status m_prev_return_status;
703*6467f958SSadaf Ebrahimi   const void *m_pIn_buf;
704*6467f958SSadaf Ebrahimi   void *m_pOut_buf;
705*6467f958SSadaf Ebrahimi   size_t *m_pIn_buf_size, *m_pOut_buf_size;
706*6467f958SSadaf Ebrahimi   tdefl_flush m_flush;
707*6467f958SSadaf Ebrahimi   const mz_uint8 *m_pSrc;
708*6467f958SSadaf Ebrahimi   size_t m_src_buf_left, m_out_buf_ofs;
709*6467f958SSadaf Ebrahimi   mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1];
710*6467f958SSadaf Ebrahimi   mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
711*6467f958SSadaf Ebrahimi   mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
712*6467f958SSadaf Ebrahimi   mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
713*6467f958SSadaf Ebrahimi   mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE];
714*6467f958SSadaf Ebrahimi   mz_uint16 m_next[TDEFL_LZ_DICT_SIZE];
715*6467f958SSadaf Ebrahimi   mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE];
716*6467f958SSadaf Ebrahimi   mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
717*6467f958SSadaf Ebrahimi } tdefl_compressor;
718*6467f958SSadaf Ebrahimi 
719*6467f958SSadaf Ebrahimi // Initializes the compressor.
720*6467f958SSadaf Ebrahimi // There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory.
721*6467f958SSadaf Ebrahimi // 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.
722*6467f958SSadaf Ebrahimi // If pBut_buf_func is NULL the user should always call the tdefl_compress() API.
723*6467f958SSadaf Ebrahimi // flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.)
724*6467f958SSadaf Ebrahimi tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
725*6467f958SSadaf Ebrahimi 
726*6467f958SSadaf Ebrahimi // 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.
727*6467f958SSadaf Ebrahimi 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);
728*6467f958SSadaf Ebrahimi 
729*6467f958SSadaf Ebrahimi // tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr.
730*6467f958SSadaf Ebrahimi // tdefl_compress_buffer() always consumes the entire input buffer.
731*6467f958SSadaf Ebrahimi tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush);
732*6467f958SSadaf Ebrahimi 
733*6467f958SSadaf Ebrahimi tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
734*6467f958SSadaf Ebrahimi mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
735*6467f958SSadaf Ebrahimi 
736*6467f958SSadaf Ebrahimi // Can't use tdefl_create_comp_flags_from_zip_params if MINIZ_NO_ZLIB_APIS isn't defined, because it uses some of its macros.
737*6467f958SSadaf Ebrahimi #ifndef MINIZ_NO_ZLIB_APIS
738*6467f958SSadaf Ebrahimi // Create tdefl_compress() flags given zlib-style compression parameters.
739*6467f958SSadaf Ebrahimi // level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files)
740*6467f958SSadaf Ebrahimi // window_bits may be -15 (raw deflate) or 15 (zlib)
741*6467f958SSadaf Ebrahimi // strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED
742*6467f958SSadaf Ebrahimi mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
743*6467f958SSadaf Ebrahimi #endif // #ifndef MINIZ_NO_ZLIB_APIS
744*6467f958SSadaf Ebrahimi 
745*6467f958SSadaf Ebrahimi #ifdef __cplusplus
746*6467f958SSadaf Ebrahimi }
747*6467f958SSadaf Ebrahimi #endif
748*6467f958SSadaf Ebrahimi 
749*6467f958SSadaf Ebrahimi #endif // MINIZ_HEADER_INCLUDED
750