29#pragma warning(disable:4242)
31#pragma warning(disable:4244)
33#pragma warning(disable:4365)
35#pragma warning(disable:4548)
37#pragma warning(disable:4061)
39#pragma warning(disable:4334)
41#pragma warning(disable:5039)
59 mz_uint32 i,
s1 = (mz_uint32)(adler & 0xffff),
s2 = (mz_uint32)(adler >> 16);
60 size_t block_len = buf_len % 5552;
65 for(i = 0; i + 7 < block_len; i += 8, ptr += 8)
76 for(; i < block_len; ++i)
78 s1 %= 65521U,
s2 %= 65521U;
82 return (
s2 << 16) +
s1;
89 static const mz_uint32 s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
90 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c };
91 mz_uint32 crcu32 = (mz_uint32)crc;
98 crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b & 0xF)];
99 crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b >> 4)];
108 static const mz_uint32 s_crc_table[256] =
110 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535,
111 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD,
112 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D,
113 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
114 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,
115 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C,
116 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC,
117 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
118 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB,
119 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
120 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB,
121 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
122 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA,
123 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE,
124 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,
125 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
126 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409,
127 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
128 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739,
129 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
130 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268,
131 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0,
132 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8,
133 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
134 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,
135 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703,
136 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7,
137 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
138 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE,
139 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
140 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6,
141 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
142 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D,
143 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5,
144 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
145 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
146 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
149 mz_uint32
crc32 = (mz_uint32)crc ^ 0xFFFFFFFF;
150 const mz_uint8 *pByte_buf = (
const mz_uint8 *)ptr;
178#ifndef MINIZ_NO_ZLIB_APIS
182 (void)opaque, (
void)items, (void)size;
183 return MZ_MALLOC(items * size);
187 (void)opaque, (
void)address;
192 (void)opaque, (
void)address, (void)items, (
void)size;
193 return MZ_REALLOC(address, items * size);
208 tdefl_compressor *pComp;
227 pComp = (tdefl_compressor *)pStream->
zalloc(pStream->
opaque, 1,
sizeof(tdefl_compressor));
231 pStream->
state = (
struct mz_internal_state *)pComp;
233 if(
tdefl_init(pComp, NULL, NULL, comp_flags) != TDEFL_STATUS_OKAY)
244 if((!pStream) || (!pStream->
state) || (!pStream->
zalloc) || (!pStream->
zfree))
247 tdefl_init((tdefl_compressor *)pStream->
state, NULL, NULL, ((tdefl_compressor *)pStream->
state)->m_flags);
253 size_t in_bytes, out_bytes;
254 mz_ulong orig_total_in, orig_total_out;
255 int mz_status =
MZ_OK;
265 if(((tdefl_compressor *)pStream->
state)->m_prev_return_status == TDEFL_STATUS_DONE)
272 tdefl_status defl_status;
277 pStream->
next_in += (mz_uint)in_bytes;
278 pStream->
avail_in -= (mz_uint)in_bytes;
279 pStream->
total_in += (mz_uint)in_bytes;
282 pStream->
next_out += (mz_uint)out_bytes;
283 pStream->
avail_out -= (mz_uint)out_bytes;
284 pStream->
total_out += (mz_uint)out_bytes;
291 else if(defl_status == TDEFL_STATUS_DONE)
300 if((flush) || (pStream->
total_in != orig_total_in) || (pStream->
total_out != orig_total_out))
316 pStream->
state = NULL;
325 return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5);
332 memset(&stream, 0,
sizeof(stream));
335 if((source_len | *pDest_len) > 0xFFFFFFFFU)
339 stream.
avail_in = (mz_uint32)source_len;
341 stream.
avail_out = (mz_uint32) * pDest_len;
400 pStream->
state = (
struct mz_internal_state *)pDecomp;
421 mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32;
422 size_t in_bytes, out_bytes, orig_avail_in;
425 if((!pStream) || (!pStream->
state))
434 decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER;
449 decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;
454 pStream->
next_in += (mz_uint)in_bytes;
455 pStream->
avail_in -= (mz_uint)in_bytes;
456 pStream->
total_in += (mz_uint)in_bytes;
458 pStream->
next_out += (mz_uint)out_bytes;
459 pStream->
avail_out -= (mz_uint)out_bytes;
460 pStream->
total_out += (mz_uint)out_bytes;
464 else if(status != TINFL_STATUS_DONE)
473 decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT;
490 out_bytes = TINFL_LZ_DICT_SIZE - pState->
m_dict_ofs;
495 pStream->
next_in += (mz_uint)in_bytes;
496 pStream->
avail_in -= (mz_uint)in_bytes;
497 pStream->
total_in += (mz_uint)in_bytes;
512 else if((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in))
517 if(status == TINFL_STATUS_DONE)
537 pStream->
state = NULL;
546 memset(&stream, 0,
sizeof(stream));
549 if((source_len | *pDest_len) > 0xFFFFFFFFU)
553 stream.
avail_in = (mz_uint32)source_len;
555 stream.
avail_out = (mz_uint32) * pDest_len;
580 {
MZ_OK,
"" }, {
MZ_STREAM_END,
"stream end" }, {
MZ_NEED_DICT,
"need dictionary" }, {
MZ_ERRNO,
"file error" }, {
MZ_STREAM_ERROR,
"stream error" },
584 for(i = 0; i <
sizeof(s_error_descs) /
sizeof(s_error_descs[0]); ++i)
585 if(s_error_descs[i].m_err == err)
586 return s_error_descs[i].m_pDesc;
660 257, 258, 259, 260, 261, 262, 263, 264, 265, 265, 266, 266, 267, 267, 268, 268, 269, 269, 269, 269, 270, 270, 270, 270, 271, 271, 271, 271, 272, 272, 272, 272,
661 273, 273, 273, 273, 273, 273, 273, 273, 274, 274, 274, 274, 274, 274, 274, 274, 275, 275, 275, 275, 275, 275, 275, 275, 276, 276, 276, 276, 276, 276, 276, 276,
662 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
663 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 279, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280, 280,
664 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, 281,
665 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282,
666 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283, 283,
667 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 285
672 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
673 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
674 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
675 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0
680 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11,
681 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13,
682 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
683 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
684 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
685 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
686 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
687 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
688 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
689 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
690 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
691 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17
696 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
697 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
698 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
699 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
700 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
701 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
702 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
703 7, 7, 7, 7, 7, 7, 7, 7
708 0, 0, 18, 19, 20, 20, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
709 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
710 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
715 0, 0, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
716 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
717 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13
727 mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2];
730 for(i = 0; i < num_syms; i++)
732 mz_uint freq = pSyms0[i].
m_key;
734 hist[256 + ((freq >> 8) & 0xFF)]++;
736 while((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256]))
738 for(pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8)
740 const mz_uint32 *pHist = &hist[pass << 8];
741 mz_uint offsets[256], cur_ofs = 0;
742 for(i = 0; i < 256; i++)
744 offsets[i] = cur_ofs;
747 for(i = 0; i < num_syms; i++)
748 pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
751 pCur_syms = pNew_syms;
761 int root, leaf, next, avbl, used, dpth;
772 for(next = 1; next < n - 1; next++)
774 if(leaf >= n || A[root].m_key < A[leaf].m_key)
777 A[root++].
m_key = (mz_uint16)next;
781 if(leaf >= n || (root < next && A[root].m_key < A[leaf].m_key))
783 A[next].
m_key = (mz_uint16)(A[next].m_key + A[root].m_key);
784 A[root++].
m_key = (mz_uint16)next;
787 A[next].
m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key);
790 for(next = n - 3; next >= 0; next--)
791 A[next].m_key = A[A[next].m_key].m_key + 1;
798 while(root >= 0 && (
int)A[root].m_key == dpth)
805 A[next--].
m_key = (mz_uint16)(dpth);
823 if(code_list_len <= 1)
826 pNum_codes[max_code_size] += pNum_codes[i];
827 for(i = max_code_size; i > 0; i--)
828 total += (((mz_uint32)pNum_codes[i]) << (max_code_size - i));
829 while(total != (1UL << max_code_size))
831 pNum_codes[max_code_size]--;
832 for(i = max_code_size - 1; i > 0; i--)
836 pNum_codes[i + 1] += 2;
847 MZ_CLEAR_OBJ(num_codes);
850 for(i = 0; i < table_len; i++)
851 num_codes[d->m_huff_code_sizes[table_num][i]]++;
855 tdefl_sym_freq syms0[TDEFL_MAX_HUFF_SYMBOLS], syms1[TDEFL_MAX_HUFF_SYMBOLS], *pSyms;
856 int num_used_syms = 0;
857 const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0];
858 for(i = 0; i < table_len; i++)
861 syms0[num_used_syms].
m_key = (mz_uint16)pSym_count[i];
868 for(i = 0; i < num_used_syms; i++)
869 num_codes[pSyms[i].m_key]++;
873 MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]);
874 MZ_CLEAR_OBJ(d->m_huff_codes[table_num]);
875 for(i = 1, j = num_used_syms; i <= code_size_limit; i++)
876 for(l = num_codes[i]; l > 0; l--)
877 d->m_huff_code_sizes[table_num][pSyms[--j].
m_sym_index] = (mz_uint8)(i);
881 for(j = 0, i = 2; i <= code_size_limit; i++)
882 next_code[i] = j = ((j + num_codes[i - 1]) << 1);
884 for(i = 0; i < table_len; i++)
886 mz_uint rev_code = 0, code, code_size;
887 if((code_size = d->m_huff_code_sizes[table_num][i]) == 0)
889 code = next_code[code_size]++;
890 for(l = code_size; l > 0; l--, code >>= 1)
891 rev_code = (rev_code << 1) | (code & 1);
892 d->m_huff_codes[table_num][i] = (mz_uint16)rev_code;
896#define TDEFL_PUT_BITS(b, l) \
901 MZ_ASSERT(bits <= ((1U << len) - 1U)); \
902 d->m_bit_buffer |= (bits << d->m_bits_in); \
903 d->m_bits_in += len; \
904 while(d->m_bits_in >= 8) \
906 if(d->m_pOutput_buf < d->m_pOutput_buf_end) \
907 *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \
908 d->m_bit_buffer >>= 8; \
914#define TDEFL_RLE_PREV_CODE_SIZE() \
916 if(rle_repeat_count) \
918 if(rle_repeat_count < 3) \
920 d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \
921 while(rle_repeat_count--) \
922 packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \
926 d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); \
927 packed_code_sizes[num_packed_code_sizes++] = 16; \
928 packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \
930 rle_repeat_count = 0; \
934#define TDEFL_RLE_ZERO_CODE_SIZE() \
938 if(rle_z_count < 3) \
940 d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); \
941 while(rle_z_count--) \
942 packed_code_sizes[num_packed_code_sizes++] = 0; \
944 else if(rle_z_count <= 10) \
946 d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); \
947 packed_code_sizes[num_packed_code_sizes++] = 17; \
948 packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \
952 d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); \
953 packed_code_sizes[num_packed_code_sizes++] = 18; \
954 packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \
960static mz_uint8
s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
964 int num_lit_codes, num_dist_codes, num_bit_lengths;
965 mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_index;
966 mz_uint8 code_sizes_to_pack[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], packed_code_sizes[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], prev_code_size = 0xFF;
968 d->m_huff_count[0][256] = 1;
973 for(num_lit_codes = 286; num_lit_codes > 257; num_lit_codes--)
974 if(d->m_huff_code_sizes[0][num_lit_codes - 1])
976 for(num_dist_codes = 30; num_dist_codes > 1; num_dist_codes--)
977 if(d->m_huff_code_sizes[1][num_dist_codes - 1])
980 memcpy(code_sizes_to_pack, &d->m_huff_code_sizes[0][0], num_lit_codes);
981 memcpy(code_sizes_to_pack + num_lit_codes, &d->m_huff_code_sizes[1][0], num_dist_codes);
982 total_code_sizes_to_pack = num_lit_codes + num_dist_codes;
983 num_packed_code_sizes = 0;
985 rle_repeat_count = 0;
987 memset(&d->m_huff_count[2][0], 0,
sizeof(d->m_huff_count[2][0]) * TDEFL_MAX_HUFF_SYMBOLS_2);
988 for(i = 0; i < total_code_sizes_to_pack; i++)
990 mz_uint8 code_size = code_sizes_to_pack[i];
994 if(++rle_z_count == 138)
1002 if(code_size != prev_code_size)
1005 d->m_huff_count[2][code_size] = (mz_uint16)(d->m_huff_count[2][code_size] + 1);
1006 packed_code_sizes[num_packed_code_sizes++] = code_size;
1008 else if(++rle_repeat_count == 6)
1013 prev_code_size = code_size;
1015 if(rle_repeat_count)
1031 for(num_bit_lengths = 18; num_bit_lengths >= 0; num_bit_lengths--)
1034 num_bit_lengths = MZ_MAX(4, (num_bit_lengths + 1));
1036 for(i = 0; (int)i < num_bit_lengths; i++)
1039 for(packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes;)
1041 mz_uint code = packed_code_sizes[packed_code_sizes_index++];
1042 MZ_ASSERT(code < TDEFL_MAX_HUFF_SYMBOLS_2);
1043 TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]);
1045 TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++],
"\02\03\07"[code - 16]);
1052 mz_uint8 *p = &d->m_huff_code_sizes[0][0];
1054 for(i = 0; i <= 143; ++i)
1056 for(; i <= 255; ++i)
1058 for(; i <= 279; ++i)
1060 for(; i <= 287; ++i)
1063 memset(d->m_huff_code_sizes[1], 5, 32);
1071static const mz_uint
mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
1073#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES &&MINIZ_LITTLE_ENDIAN &&MINIZ_HAS_64BIT_REGISTERS
1077 mz_uint8 *pLZ_codes;
1078 mz_uint8 *pOutput_buf = d->m_pOutput_buf;
1079 mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf;
1080 mz_uint64 bit_buffer = d->m_bit_buffer;
1081 mz_uint bits_in = d->m_bits_in;
1083#define TDEFL_PUT_BITS_FAST(b, l) \
1085 bit_buffer |= (((mz_uint64)(b)) << bits_in); \
1090 for(pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1)
1093 flags = *pLZ_codes++ | 0x100;
1097 mz_uint s0,
s1, n0, n1, sym, num_extra_bits;
1098 mz_uint match_len = pLZ_codes[0], match_dist = *(
const mz_uint16 *)(pLZ_codes + 1);
1110 sym = (match_dist < 512) ? s0 :
s1;
1111 num_extra_bits = (match_dist < 512) ? n0 : n1;
1113 MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
1114 TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
1115 TDEFL_PUT_BITS_FAST(match_dist &
mz_bitmasks[num_extra_bits], num_extra_bits);
1119 mz_uint lit = *pLZ_codes++;
1120 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1121 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1123 if(((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
1127 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1128 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1130 if(((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
1134 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1135 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1140 if(pOutput_buf >= d->m_pOutput_buf_end)
1143 *(mz_uint64 *)pOutput_buf = bit_buffer;
1144 pOutput_buf += (bits_in >> 3);
1145 bit_buffer >>= (bits_in & ~7);
1149#undef TDEFL_PUT_BITS_FAST
1151 d->m_pOutput_buf = pOutput_buf;
1153 d->m_bit_buffer = 0;
1157 mz_uint32 n = MZ_MIN(bits_in, 16);
1163 TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
1165 return (d->m_pOutput_buf < d->m_pOutput_buf_end);
1171 mz_uint8 *pLZ_codes;
1174 for(pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1)
1177 flags = *pLZ_codes++ | 0x100;
1180 mz_uint sym, num_extra_bits;
1181 mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8));
1188 if(match_dist < 512)
1198 MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
1199 TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
1204 mz_uint lit = *pLZ_codes++;
1205 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1206 TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1210 TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
1212 return (d->m_pOutput_buf < d->m_pOutput_buf_end);
1227 mz_uint saved_bit_buf, saved_bits_in;
1228 mz_uint8 *pSaved_output_buf;
1229 mz_bool comp_block_succeeded = MZ_FALSE;
1230 int n, use_raw_block = ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size;
1231 mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE)) ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf;
1233 d->m_pOutput_buf = pOutput_buf_start;
1234 d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16;
1236 MZ_ASSERT(!d->m_output_flush_remaining);
1237 d->m_output_flush_ofs = 0;
1238 d->m_output_flush_remaining = 0;
1240 *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left);
1241 d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);
1243 if((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index))
1251 pSaved_output_buf = d->m_pOutput_buf;
1252 saved_bit_buf = d->m_bit_buffer;
1253 saved_bits_in = d->m_bits_in;
1256 comp_block_succeeded =
tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48));
1259 if(((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) &&
1260 ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size))
1263 d->m_pOutput_buf = pSaved_output_buf;
1264 d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
1270 for(i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF)
1274 for(i = 0; i < d->m_total_lz_bytes; ++i)
1276 TDEFL_PUT_BITS(d->m_dict[(d->m_lz_code_buf_dict_pos + i) & TDEFL_LZ_DICT_SIZE_MASK], 8);
1280 else if(!comp_block_succeeded)
1282 d->m_pOutput_buf = pSaved_output_buf;
1283 d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
1289 if(flush == TDEFL_FINISH)
1295 if(d->m_flags & TDEFL_WRITE_ZLIB_HEADER)
1297 mz_uint i, a = d->m_adler32;
1298 for(i = 0; i < 4; i++)
1313 for(i = 2; i; --i, z ^= 0xFFFF)
1320 MZ_ASSERT(d->m_pOutput_buf < d->m_pOutput_buf_end);
1322 memset(&d->m_huff_count[0][0], 0,
sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
1323 memset(&d->m_huff_count[1][0], 0,
sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);
1325 d->m_pLZ_code_buf = d->m_lz_code_buf + 1;
1326 d->m_pLZ_flags = d->m_lz_code_buf;
1327 d->m_num_flags_left = 8;
1328 d->m_lz_code_buf_dict_pos += d->m_total_lz_bytes;
1329 d->m_total_lz_bytes = 0;
1332 if((n = (
int)(d->m_pOutput_buf - pOutput_buf_start)) != 0)
1334 if(d->m_pPut_buf_func)
1336 *d->m_pIn_buf_size = d->m_pSrc - (
const mz_uint8 *)d->m_pIn_buf;
1337 if(!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user))
1338 return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED);
1340 else if(pOutput_buf_start == d->m_output_buf)
1342 int bytes_to_copy = (int)MZ_MIN((
size_t)n, (
size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs));
1343 memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy);
1344 d->m_out_buf_ofs += bytes_to_copy;
1345 if((n -= bytes_to_copy) != 0)
1347 d->m_output_flush_ofs = bytes_to_copy;
1348 d->m_output_flush_remaining = n;
1353 d->m_out_buf_ofs += n;
1357 return d->m_output_flush_remaining;
1360#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
1361#define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16 *)(p)
1362static MZ_FORCEINLINE
void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
1364 mz_uint dist,
pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos =
pos, next_probe_pos, probe_len;
1365 mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
1366 const mz_uint16 *s = (
const mz_uint16 *)(d->m_dict +
pos), *p, *q;
1367 mz_uint16 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[
pos + match_len - 1]), s01 = TDEFL_READ_UNALIGNED_WORD(s);
1368 MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN);
1369 if(max_match_len <= match_len)
1375 if(--num_probes_left == 0)
1377#define TDEFL_PROBE \
1378 next_probe_pos = d->m_next[probe_pos]; \
1379 if((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) \
1381 probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
1382 if(TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) \
1390 q = (
const mz_uint16 *)(d->m_dict + probe_pos);
1391 if(TDEFL_READ_UNALIGNED_WORD(q) != s01)
1397 }
while((TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) &&
1398 (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0));
1401 *pMatch_dist = dist;
1402 *pMatch_len = MZ_MIN(max_match_len, (mz_uint)TDEFL_MAX_MATCH_LEN);
1405 else if((probe_len = ((mz_uint)(p - s) * 2) + (mz_uint)(*(
const mz_uint8 *)p == *(
const mz_uint8 *)q)) > match_len)
1407 *pMatch_dist = dist;
1408 if((*pMatch_len = match_len = MZ_MIN(max_match_len, probe_len)) == max_match_len)
1410 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[
pos + match_len - 1]);
1415static MZ_FORCEINLINE
void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
1417 mz_uint dist,
pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos =
pos, next_probe_pos, probe_len;
1418 mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
1419 const mz_uint8 *s = d->m_dict +
pos, *p, *q;
1420 mz_uint8 c0 = d->m_dict[
pos + match_len], c1 = d->m_dict[
pos + match_len - 1];
1421 MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN);
1422 if(max_match_len <= match_len)
1428 if(--num_probes_left == 0)
1430#define TDEFL_PROBE \
1431 next_probe_pos = d->m_next[probe_pos]; \
1432 if((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) \
1434 probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
1435 if((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) \
1444 q = d->m_dict + probe_pos;
1445 for(probe_len = 0; probe_len < max_match_len; probe_len++)
1448 if(probe_len > match_len)
1450 *pMatch_dist = dist;
1451 if((*pMatch_len = match_len = probe_len) == max_match_len)
1453 c0 = d->m_dict[
pos + match_len];
1454 c1 = d->m_dict[
pos + match_len - 1];
1460#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES &&MINIZ_LITTLE_ENDIAN
1461static mz_bool tdefl_compress_fast(tdefl_compressor *d)
1464 mz_uint lookahead_pos = d->m_lookahead_pos, lookahead_size = d->m_lookahead_size, dict_size = d->m_dict_size, total_lz_bytes = d->m_total_lz_bytes, num_flags_left = d->m_num_flags_left;
1465 mz_uint8 *pLZ_code_buf = d->m_pLZ_code_buf, *pLZ_flags = d->m_pLZ_flags;
1466 mz_uint cur_pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK;
1468 while((d->m_src_buf_left) || ((d->m_flush) && (lookahead_size)))
1470 const mz_uint TDEFL_COMP_FAST_LOOKAHEAD_SIZE = 4096;
1471 mz_uint dst_pos = (lookahead_pos + lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK;
1472 mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(d->m_src_buf_left, TDEFL_COMP_FAST_LOOKAHEAD_SIZE - lookahead_size);
1473 d->m_src_buf_left -= num_bytes_to_process;
1474 lookahead_size += num_bytes_to_process;
1476 while(num_bytes_to_process)
1478 mz_uint32 n = MZ_MIN(TDEFL_LZ_DICT_SIZE - dst_pos, num_bytes_to_process);
1479 memcpy(d->m_dict + dst_pos, d->m_pSrc, n);
1480 if(dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
1481 memcpy(d->m_dict + TDEFL_LZ_DICT_SIZE + dst_pos, d->m_pSrc, MZ_MIN(n, (TDEFL_MAX_MATCH_LEN - 1) - dst_pos));
1483 dst_pos = (dst_pos + n) & TDEFL_LZ_DICT_SIZE_MASK;
1484 num_bytes_to_process -= n;
1487 dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - lookahead_size, dict_size);
1488 if((!d->m_flush) && (lookahead_size < TDEFL_COMP_FAST_LOOKAHEAD_SIZE))
1491 while(lookahead_size >= 4)
1493 mz_uint cur_match_dist, cur_match_len = 1;
1494 mz_uint8 *pCur_dict = d->m_dict + cur_pos;
1495 mz_uint first_trigram = (*(
const mz_uint32 *)pCur_dict) & 0xFFFFFF;
1496 mz_uint hash = (first_trigram ^ (first_trigram >> (24 - (TDEFL_LZ_HASH_BITS - 8)))) & TDEFL_LEVEL1_HASH_SIZE_MASK;
1497 mz_uint probe_pos = d->m_hash[hash];
1498 d->m_hash[hash] = (mz_uint16)lookahead_pos;
1500 if(((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((*(
const mz_uint32 *)(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram))
1502 const mz_uint16 *p = (
const mz_uint16 *)pCur_dict;
1503 const mz_uint16 *q = (
const mz_uint16 *)(d->m_dict + probe_pos);
1504 mz_uint32 probe_len = 32;
1507 }
while((TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) &&
1508 (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0));
1509 cur_match_len = ((mz_uint)(p - (
const mz_uint16 *)pCur_dict) * 2) + (mz_uint)(*(
const mz_uint8 *)p == *(
const mz_uint8 *)q);
1511 cur_match_len = cur_match_dist ? TDEFL_MAX_MATCH_LEN : 0;
1513 if((cur_match_len < TDEFL_MIN_MATCH_LEN) || ((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U * 1024U)))
1516 *pLZ_code_buf++ = (mz_uint8)first_trigram;
1517 *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1);
1518 d->m_huff_count[0][(mz_uint8)first_trigram]++;
1523 cur_match_len = MZ_MIN(cur_match_len, lookahead_size);
1525 MZ_ASSERT((cur_match_len >= TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 1) && (cur_match_dist <= TDEFL_LZ_DICT_SIZE));
1529 pLZ_code_buf[0] = (mz_uint8)(cur_match_len - TDEFL_MIN_MATCH_LEN);
1530 *(mz_uint16 *)(&pLZ_code_buf[1]) = (mz_uint16)cur_match_dist;
1532 *pLZ_flags = (mz_uint8)((*pLZ_flags >> 1) | 0x80);
1536 d->m_huff_count[1][(cur_match_dist < 512) ? s0 :
s1]++;
1538 d->m_huff_count[0][
s_tdefl_len_sym[cur_match_len - TDEFL_MIN_MATCH_LEN]]++;
1543 *pLZ_code_buf++ = (mz_uint8)first_trigram;
1544 *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1);
1545 d->m_huff_count[0][(mz_uint8)first_trigram]++;
1548 if(--num_flags_left == 0)
1551 pLZ_flags = pLZ_code_buf++;
1554 total_lz_bytes += cur_match_len;
1555 lookahead_pos += cur_match_len;
1556 dict_size = MZ_MIN(dict_size + cur_match_len, (mz_uint)TDEFL_LZ_DICT_SIZE);
1557 cur_pos = (cur_pos + cur_match_len) & TDEFL_LZ_DICT_SIZE_MASK;
1558 MZ_ASSERT(lookahead_size >= cur_match_len);
1559 lookahead_size -= cur_match_len;
1561 if(pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8])
1564 d->m_lookahead_pos = lookahead_pos;
1565 d->m_lookahead_size = lookahead_size;
1566 d->m_dict_size = dict_size;
1567 d->m_total_lz_bytes = total_lz_bytes;
1568 d->m_pLZ_code_buf = pLZ_code_buf;
1569 d->m_pLZ_flags = pLZ_flags;
1570 d->m_num_flags_left = num_flags_left;
1572 return (n < 0) ? MZ_FALSE : MZ_TRUE;
1573 total_lz_bytes = d->m_total_lz_bytes;
1574 pLZ_code_buf = d->m_pLZ_code_buf;
1575 pLZ_flags = d->m_pLZ_flags;
1576 num_flags_left = d->m_num_flags_left;
1580 while(lookahead_size)
1582 mz_uint8 lit = d->m_dict[cur_pos];
1585 *pLZ_code_buf++ = lit;
1586 *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1);
1587 if(--num_flags_left == 0)
1590 pLZ_flags = pLZ_code_buf++;
1593 d->m_huff_count[0][lit]++;
1596 dict_size = MZ_MIN(dict_size + 1, (mz_uint)TDEFL_LZ_DICT_SIZE);
1597 cur_pos = (cur_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK;
1600 if(pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8])
1603 d->m_lookahead_pos = lookahead_pos;
1604 d->m_lookahead_size = lookahead_size;
1605 d->m_dict_size = dict_size;
1606 d->m_total_lz_bytes = total_lz_bytes;
1607 d->m_pLZ_code_buf = pLZ_code_buf;
1608 d->m_pLZ_flags = pLZ_flags;
1609 d->m_num_flags_left = num_flags_left;
1611 return (n < 0) ? MZ_FALSE : MZ_TRUE;
1612 total_lz_bytes = d->m_total_lz_bytes;
1613 pLZ_code_buf = d->m_pLZ_code_buf;
1614 pLZ_flags = d->m_pLZ_flags;
1615 num_flags_left = d->m_num_flags_left;
1620 d->m_lookahead_pos = lookahead_pos;
1621 d->m_lookahead_size = lookahead_size;
1622 d->m_dict_size = dict_size;
1623 d->m_total_lz_bytes = total_lz_bytes;
1624 d->m_pLZ_code_buf = pLZ_code_buf;
1625 d->m_pLZ_flags = pLZ_flags;
1626 d->m_num_flags_left = num_flags_left;
1633 d->m_total_lz_bytes++;
1634 *d->m_pLZ_code_buf++ = lit;
1635 *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> 1);
1636 if(--d->m_num_flags_left == 0)
1638 d->m_num_flags_left = 8;
1639 d->m_pLZ_flags = d->m_pLZ_code_buf++;
1641 d->m_huff_count[0][lit]++;
1648 MZ_ASSERT((match_len >= TDEFL_MIN_MATCH_LEN) && (match_dist >= 1) && (match_dist <= TDEFL_LZ_DICT_SIZE));
1650 d->m_total_lz_bytes += match_len;
1652 d->m_pLZ_code_buf[0] = (mz_uint8)(match_len - TDEFL_MIN_MATCH_LEN);
1655 d->m_pLZ_code_buf[1] = (mz_uint8)(match_dist & 0xFF);
1656 d->m_pLZ_code_buf[2] = (mz_uint8)(match_dist >> 8);
1657 d->m_pLZ_code_buf += 3;
1659 *d->m_pLZ_flags = (mz_uint8)((*d->m_pLZ_flags >> 1) | 0x80);
1660 if(--d->m_num_flags_left == 0)
1662 d->m_num_flags_left = 8;
1663 d->m_pLZ_flags = d->m_pLZ_code_buf++;
1668 d->m_huff_count[1][(match_dist < 512) ? s0 :
s1]++;
1670 if(match_len >= TDEFL_MIN_MATCH_LEN)
1671 d->m_huff_count[0][
s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++;
1676 const mz_uint8 *pSrc = d->m_pSrc;
1677 size_t src_buf_left = d->m_src_buf_left;
1678 tdefl_flush flush = d->m_flush;
1680 while((src_buf_left) || ((flush) && (d->m_lookahead_size)))
1682 mz_uint len_to_move, cur_match_dist, cur_match_len, cur_pos;
1684 if((d->m_lookahead_size + d->m_dict_size) >= (TDEFL_MIN_MATCH_LEN - 1))
1686 mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK, ins_pos = d->m_lookahead_pos + d->m_lookahead_size - 2;
1687 mz_uint hash = (d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK];
1688 mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(src_buf_left, TDEFL_MAX_MATCH_LEN - d->m_lookahead_size);
1689 const mz_uint8 *pSrc_end = pSrc + num_bytes_to_process;
1690 src_buf_left -= num_bytes_to_process;
1691 d->m_lookahead_size += num_bytes_to_process;
1692 while(pSrc != pSrc_end)
1694 mz_uint8 c = *pSrc++;
1695 d->m_dict[dst_pos] = c;
1696 if(dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
1697 d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c;
1698 hash = ((hash << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1);
1699 d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash];
1700 d->m_hash[hash] = (mz_uint16)(ins_pos);
1701 dst_pos = (dst_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK;
1707 while((src_buf_left) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN))
1709 mz_uint8 c = *pSrc++;
1710 mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK;
1712 d->m_dict[dst_pos] = c;
1713 if(dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
1714 d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c;
1715 if((++d->m_lookahead_size + d->m_dict_size) >= TDEFL_MIN_MATCH_LEN)
1717 mz_uint ins_pos = d->m_lookahead_pos + (d->m_lookahead_size - 1) - 2;
1718 mz_uint hash = ((d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << (TDEFL_LZ_HASH_SHIFT * 2)) ^ (d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1);
1719 d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash];
1720 d->m_hash[hash] = (mz_uint16)(ins_pos);
1724 d->m_dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - d->m_lookahead_size, d->m_dict_size);
1725 if((!flush) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN))
1731 cur_match_len = d->m_saved_match_len ? d->m_saved_match_len : (TDEFL_MIN_MATCH_LEN - 1);
1732 cur_pos = d->m_lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK;
1733 if(d->m_flags & (TDEFL_RLE_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS))
1735 if((d->m_dict_size) && (!(d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS)))
1737 mz_uint8 c = d->m_dict[(cur_pos - 1) & TDEFL_LZ_DICT_SIZE_MASK];
1739 while(cur_match_len < d->m_lookahead_size)
1741 if(d->m_dict[cur_pos + cur_match_len] != c)
1745 if(cur_match_len < TDEFL_MIN_MATCH_LEN)
1753 tdefl_find_match(d, d->m_lookahead_pos, d->m_dict_size, d->m_lookahead_size, &cur_match_dist, &cur_match_len);
1755 if(((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U * 1024U)) || (cur_pos == cur_match_dist) || ((d->m_flags & TDEFL_FILTER_MATCHES) && (cur_match_len <= 5)))
1757 cur_match_dist = cur_match_len = 0;
1759 if(d->m_saved_match_len)
1761 if(cur_match_len > d->m_saved_match_len)
1764 if(cur_match_len >= 128)
1767 d->m_saved_match_len = 0;
1768 len_to_move = cur_match_len;
1772 d->m_saved_lit = d->m_dict[cur_pos];
1773 d->m_saved_match_dist = cur_match_dist;
1774 d->m_saved_match_len = cur_match_len;
1780 len_to_move = d->m_saved_match_len - 1;
1781 d->m_saved_match_len = 0;
1784 else if(!cur_match_dist)
1786 else if((d->m_greedy_parsing) || (d->m_flags & TDEFL_RLE_MATCHES) || (cur_match_len >= 128))
1789 len_to_move = cur_match_len;
1793 d->m_saved_lit = d->m_dict[MZ_MIN(cur_pos,
sizeof(d->m_dict) - 1)];
1794 d->m_saved_match_dist = cur_match_dist;
1795 d->m_saved_match_len = cur_match_len;
1798 d->m_lookahead_pos += len_to_move;
1799 MZ_ASSERT(d->m_lookahead_size >= len_to_move);
1800 d->m_lookahead_size -= len_to_move;
1801 d->m_dict_size = MZ_MIN(d->m_dict_size + len_to_move, (mz_uint)TDEFL_LZ_DICT_SIZE);
1803 if((d->m_pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) ||
1804 ((d->m_total_lz_bytes > 31 * 1024) && (((((mz_uint)(d->m_pLZ_code_buf - d->m_lz_code_buf) * 115) >> 7) >= d->m_total_lz_bytes) || (d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS))))
1808 d->m_src_buf_left = src_buf_left;
1810 return (n < 0) ? MZ_FALSE : MZ_TRUE;
1815 d->m_src_buf_left = src_buf_left;
1821 if(d->m_pIn_buf_size)
1823 *d->m_pIn_buf_size = d->m_pSrc - (
const mz_uint8 *)d->m_pIn_buf;
1826 if(d->m_pOut_buf_size)
1828 size_t n = MZ_MIN(*d->m_pOut_buf_size - d->m_out_buf_ofs, d->m_output_flush_remaining);
1829 memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf + d->m_output_flush_ofs, n);
1830 d->m_output_flush_ofs += (mz_uint)n;
1831 d->m_output_flush_remaining -= (mz_uint)n;
1832 d->m_out_buf_ofs += n;
1834 *d->m_pOut_buf_size = d->m_out_buf_ofs;
1837 return (d->m_finished && !d->m_output_flush_remaining) ? TDEFL_STATUS_DONE : TDEFL_STATUS_OKAY;
1840tdefl_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)
1848 return TDEFL_STATUS_BAD_PARAM;
1851 d->m_pIn_buf = pIn_buf;
1852 d->m_pIn_buf_size = pIn_buf_size;
1853 d->m_pOut_buf = pOut_buf;
1854 d->m_pOut_buf_size = pOut_buf_size;
1855 d->m_pSrc = (
const mz_uint8 *)(pIn_buf);
1856 d->m_src_buf_left = pIn_buf_size ? *pIn_buf_size : 0;
1857 d->m_out_buf_ofs = 0;
1860 if(((d->m_pPut_buf_func != NULL) == ((pOut_buf != NULL) || (pOut_buf_size != NULL))) || (d->m_prev_return_status != TDEFL_STATUS_OKAY) ||
1861 (d->m_wants_to_finish && (flush != TDEFL_FINISH)) || (pIn_buf_size && *pIn_buf_size && !pIn_buf) || (pOut_buf_size && *pOut_buf_size && !pOut_buf))
1867 return (d->m_prev_return_status = TDEFL_STATUS_BAD_PARAM);
1869 d->m_wants_to_finish |= (flush == TDEFL_FINISH);
1871 if((d->m_output_flush_remaining) || (d->m_finished))
1874#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES &&MINIZ_LITTLE_ENDIAN
1875 if(((d->m_flags & TDEFL_MAX_PROBES_MASK) == 1) &&
1876 ((d->m_flags & TDEFL_GREEDY_PARSING_FLAG) != 0) &&
1877 ((d->m_flags & (TDEFL_FILTER_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS | TDEFL_RLE_MATCHES)) == 0))
1879 if(!tdefl_compress_fast(d))
1880 return d->m_prev_return_status;
1886 return d->m_prev_return_status;
1889 if((d->m_flags & (TDEFL_WRITE_ZLIB_HEADER | TDEFL_COMPUTE_ADLER32)) && (pIn_buf))
1890 d->m_adler32 = (mz_uint32)
mz_adler32(d->m_adler32, (
const mz_uint8 *)pIn_buf, d->m_pSrc - (
const mz_uint8 *)pIn_buf);
1892 if((flush) && (!d->m_lookahead_size) && (!d->m_src_buf_left) && (!d->m_output_flush_remaining))
1895 return d->m_prev_return_status;
1896 d->m_finished = (flush == TDEFL_FINISH);
1897 if(flush == TDEFL_FULL_FLUSH)
1899 MZ_CLEAR_OBJ(d->m_hash);
1900 MZ_CLEAR_OBJ(d->m_next);
1910 MZ_ASSERT(d->m_pPut_buf_func);
1911 return tdefl_compress(d, pIn_buf, &in_buf_size, NULL, NULL, flush);
1914tdefl_status
tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func,
void *pPut_buf_user,
int flags)
1916 d->m_pPut_buf_func = pPut_buf_func;
1917 d->m_pPut_buf_user = pPut_buf_user;
1918 d->m_flags = (mz_uint)(flags);
1919 d->m_max_probes[0] = 1 + ((flags & 0xFFF) + 2) / 3;
1920 d->m_greedy_parsing = (flags & TDEFL_GREEDY_PARSING_FLAG) != 0;
1921 d->m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3;
1922 if(!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG))
1923 MZ_CLEAR_OBJ(d->m_hash);
1924 d->m_lookahead_pos = d->m_lookahead_size = d->m_dict_size = d->m_total_lz_bytes = d->m_lz_code_buf_dict_pos = d->m_bits_in = 0;
1925 d->m_output_flush_ofs = d->m_output_flush_remaining = d->m_finished = d->m_block_index = d->m_bit_buffer = d->m_wants_to_finish = 0;
1926 d->m_pLZ_code_buf = d->m_lz_code_buf + 1;
1927 d->m_pLZ_flags = d->m_lz_code_buf;
1928 d->m_num_flags_left = 8;
1929 d->m_pOutput_buf = d->m_output_buf;
1930 d->m_pOutput_buf_end = d->m_output_buf;
1931 d->m_prev_return_status = TDEFL_STATUS_OKAY;
1932 d->m_saved_match_dist = d->m_saved_match_len = d->m_saved_lit = 0;
1934 d->m_pIn_buf = NULL;
1935 d->m_pOut_buf = NULL;
1936 d->m_pIn_buf_size = NULL;
1937 d->m_pOut_buf_size = NULL;
1938 d->m_flush = TDEFL_NO_FLUSH;
1940 d->m_src_buf_left = 0;
1941 d->m_out_buf_ofs = 0;
1942 memset(&d->m_huff_count[0][0], 0,
sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
1943 memset(&d->m_huff_count[1][0], 0,
sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);
1944 return TDEFL_STATUS_OKAY;
1949 return d->m_prev_return_status;
1954 return d->m_adler32;
1959 tdefl_compressor *pComp;
1961 if(((buf_len) && (!pBuf)) || (!pPut_buf_func))
1963 pComp = (tdefl_compressor *)MZ_MALLOC(
sizeof(tdefl_compressor));
1966 succeeded = (
tdefl_init(pComp, pPut_buf_func, pPut_buf_user, flags) == TDEFL_STATUS_OKAY);
1967 succeeded = succeeded && (
tdefl_compress_buffer(pComp, pBuf, buf_len, TDEFL_FINISH) == TDEFL_STATUS_DONE);
1982 size_t new_size = p->
m_size + len;
1991 new_capacity = MZ_MAX(128U, new_capacity << 1U);
1992 }
while(new_size > new_capacity);
1993 pNew_buf = (mz_uint8 *)MZ_REALLOC(p->
m_pBuf, new_capacity);
2007 MZ_CLEAR_OBJ(out_buf);
2015 *pOut_len = out_buf.
m_size;
2022 MZ_CLEAR_OBJ(out_buf);
2025 out_buf.
m_pBuf = (mz_uint8 *)pOut_buf;
2032#ifndef MINIZ_NO_ZLIB_APIS
2033static const mz_uint
s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
2040 comp_flags |= TDEFL_WRITE_ZLIB_HEADER;
2043 comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS;
2045 comp_flags |= TDEFL_FILTER_MATCHES;
2047 comp_flags &= ~TDEFL_MAX_PROBES_MASK;
2049 comp_flags |= TDEFL_FORCE_ALL_STATIC_BLOCKS;
2050 else if(strategy ==
MZ_RLE)
2051 comp_flags |= TDEFL_RLE_MATCHES;
2058#pragma warning(push)
2059#pragma warning(disable : 4204)
2068 static const mz_uint s_tdefl_png_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
2069 tdefl_compressor *pComp = (tdefl_compressor *)MZ_MALLOC(
sizeof(tdefl_compressor));
2071 int i, bpl = w * num_chans, y, z;
2076 MZ_CLEAR_OBJ(out_buf);
2078 out_buf.
m_capacity = 57 + MZ_MAX(64, (1 + bpl) * h);
2089 for(y = 0; y < h; ++y)
2092 tdefl_compress_buffer(pComp, (mz_uint8 *)pImage + (flip ? (h - 1 - y) : y) * bpl, bpl, TDEFL_NO_FLUSH);
2101 *pLen_out = out_buf.
m_size - 41;
2103 static const mz_uint8 chans[] = { 0x00, 0x00, 0x04, 0x02, 0x06 };
2104 mz_uint8 pnghdr[41] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
2105 0, 0, (mz_uint8)(w >> 8), (mz_uint8)w, 0, 0, (mz_uint8)(h >> 8), (mz_uint8)h, 8, chans[num_chans], 0, 0, 0, 0, 0, 0, 0,
2106 (mz_uint8)(*pLen_out >> 24), (mz_uint8)(*pLen_out >> 16), (mz_uint8)(*pLen_out >> 8), (mz_uint8) * pLen_out, 0x49, 0x44, 0x41, 0x54 };
2108 for(i = 0; i < 4; ++i, c <<= 8)
2109 ((mz_uint8 *)(pnghdr + 29))[i] = (mz_uint8)(c >> 24);
2110 memcpy(out_buf.
m_pBuf, pnghdr, 41);
2121 for(i = 0; i < 4; ++i, c <<= 8)
2122 (out_buf.
m_pBuf + out_buf.
m_size - 16)[i] = (mz_uint8)(c >> 24);
2139 return (tdefl_compressor *)MZ_MALLOC(
sizeof(tdefl_compressor));
2188#define TINFL_MEMCPY(d, s, l) memcpy(d, s, l)
2189#define TINFL_MEMSET(p, c, l) memset(p, c, l)
2191#define TINFL_CR_BEGIN \
2192 switch(r->m_state) \
2195#define TINFL_CR_RETURN(state_index, result) \
2199 r->m_state = state_index; \
2205#define TINFL_CR_RETURN_FOREVER(state_index, result) \
2210 TINFL_CR_RETURN(state_index, result); \
2214#define TINFL_CR_FINISH }
2216#define TINFL_GET_BYTE(state_index, c) \
2219 while(pIn_buf_cur >= pIn_buf_end) \
2221 TINFL_CR_RETURN(state_index, (decomp_flags &TINFL_FLAG_HAS_MORE_INPUT) ? TINFL_STATUS_NEEDS_MORE_INPUT : TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS); \
2223 c = *pIn_buf_cur++; \
2227#define TINFL_NEED_BITS(state_index, n) \
2231 TINFL_GET_BYTE(state_index, c); \
2232 bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); \
2234 } while(num_bits < (mz_uint)(n))
2235#define TINFL_SKIP_BITS(state_index, n) \
2238 if(num_bits < (mz_uint)(n)) \
2240 TINFL_NEED_BITS(state_index, n); \
2246#define TINFL_GET_BITS(state_index, b, n) \
2249 if(num_bits < (mz_uint)(n)) \
2251 TINFL_NEED_BITS(state_index, n); \
2253 b = bit_buf & ((1 << (n)) - 1); \
2263#define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \
2266 temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \
2269 code_len = temp >> 9; \
2270 if((code_len) && (num_bits >= code_len)) \
2273 else if(num_bits > TINFL_FAST_LOOKUP_BITS) \
2275 code_len = TINFL_FAST_LOOKUP_BITS; \
2278 temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
2279 } while((temp < 0) && (num_bits >= (code_len + 1))); \
2283 TINFL_GET_BYTE(state_index, c); \
2284 bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); \
2286 } while(num_bits < 15);
2294#define TINFL_HUFF_DECODE(state_index, sym, pHuff) \
2298 mz_uint code_len, c; \
2301 if((pIn_buf_end - pIn_buf_cur) < 2) \
2303 TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \
2307 bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); \
2312 if((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
2313 code_len = temp >> 9, temp &= 511; \
2316 code_len = TINFL_FAST_LOOKUP_BITS; \
2319 temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
2320 } while(temp < 0); \
2323 bit_buf >>= code_len; \
2324 num_bits -= code_len; \
2328tinfl_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)
2330 static const int s_length_base[31] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 };
2331 static const int s_length_extra[31] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0 };
2332 static const int s_dist_base[32] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0 };
2333 static const int s_dist_extra[32] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 };
2334 static const mz_uint8 s_length_dezigzag[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
2335 static const int s_min_table_sizes[3] = { 257, 1, 4 };
2337 tinfl_status status = TINFL_STATUS_FAILED;
2338 mz_uint32 num_bits, dist, counter, num_extra;
2339 tinfl_bit_buf_t bit_buf;
2340 const mz_uint8 *pIn_buf_cur = pIn_buf_next, *
const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
2341 mz_uint8 *pOut_buf_cur = pOut_buf_next, *
const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
2342 size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (
size_t) - 1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start;
2345 if(((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start))
2347 *pIn_buf_size = *pOut_buf_size = 0;
2348 return TINFL_STATUS_BAD_PARAM;
2351 num_bits =
r->m_num_bits;
2352 bit_buf =
r->m_bit_buf;
2354 counter =
r->m_counter;
2355 num_extra =
r->m_num_extra;
2356 dist_from_out_buf_start =
r->m_dist_from_out_buf_start;
2359 bit_buf = num_bits = dist = counter = num_extra =
r->m_zhdr0 =
r->m_zhdr1 = 0;
2360 r->m_z_adler32 =
r->m_check_adler32 = 1;
2361 if(decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
2365 counter = (((
r->m_zhdr0 * 256 +
r->m_zhdr1) % 31 != 0) || (
r->m_zhdr1 & 32) || ((
r->m_zhdr0 & 15) != 8));
2366 if(!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
2367 counter |= (((1U << (8U + (
r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (
r->m_zhdr0 >> 4)))));
2377 r->m_type =
r->m_final >> 1;
2381 for(counter = 0; counter < 4; ++counter)
2388 if((counter = (
r->m_raw_header[0] | (
r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (
r->m_raw_header[2] | (
r->m_raw_header[3] << 8))))
2392 while((counter) && (num_bits))
2395 while(pOut_buf_cur >= pOut_buf_end)
2399 *pOut_buf_cur++ = (mz_uint8)dist;
2405 while(pOut_buf_cur >= pOut_buf_end)
2409 while(pIn_buf_cur >= pIn_buf_end)
2411 TINFL_CR_RETURN(38, (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) ? TINFL_STATUS_NEEDS_MORE_INPUT : TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS);
2413 n = MZ_MIN(MZ_MIN((
size_t)(pOut_buf_end - pOut_buf_cur), (
size_t)(pIn_buf_end - pIn_buf_cur)), counter);
2417 counter -= (mz_uint)n;
2420 else if(
r->m_type == 3)
2428 mz_uint8 *p =
r->m_tables[0].m_code_size;
2430 r->m_table_sizes[0] = 288;
2431 r->m_table_sizes[1] = 32;
2433 for(i = 0; i <= 143; ++i)
2435 for(; i <= 255; ++i)
2437 for(; i <= 279; ++i)
2439 for(; i <= 287; ++i)
2444 for(counter = 0; counter < 3; counter++)
2447 r->m_table_sizes[counter] += s_min_table_sizes[counter];
2449 MZ_CLEAR_OBJ(
r->m_tables[2].m_code_size);
2450 for(counter = 0; counter <
r->m_table_sizes[2]; counter++)
2454 r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s;
2456 r->m_table_sizes[2] = 19;
2458 for(; (int)
r->m_type >= 0;
r->m_type--)
2460 int tree_next, tree_cur;
2461 tinfl_huff_table *pTable;
2462 mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16];
2463 pTable = &
r->m_tables[
r->m_type];
2464 MZ_CLEAR_OBJ(total_syms);
2465 MZ_CLEAR_OBJ(pTable->m_look_up);
2466 MZ_CLEAR_OBJ(pTable->m_tree);
2467 for(i = 0; i <
r->m_table_sizes[
r->m_type]; ++i)
2468 total_syms[pTable->m_code_size[i]]++;
2469 used_syms = 0, total = 0;
2470 next_code[0] = next_code[1] = 0;
2471 for(i = 1; i <= 15; ++i)
2473 used_syms += total_syms[i];
2474 next_code[i + 1] = (total = ((total + total_syms[i]) << 1));
2476 if((65536 != total) && (used_syms > 1))
2480 for(tree_next = -1, sym_index = 0; sym_index <
r->m_table_sizes[
r->m_type]; ++sym_index)
2482 mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index];
2485 cur_code = next_code[code_size]++;
2486 for(l = code_size; l > 0; l--, cur_code >>= 1)
2487 rev_code = (rev_code << 1) | (cur_code & 1);
2488 if(code_size <= TINFL_FAST_LOOKUP_BITS)
2490 mz_int16 k = (mz_int16)((code_size << 9) | sym_index);
2491 while(rev_code < TINFL_FAST_LOOKUP_SIZE)
2493 pTable->m_look_up[rev_code] = k;
2494 rev_code += (1 << code_size);
2498 if(0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)]))
2500 pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next;
2501 tree_cur = tree_next;
2504 rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
2505 for(j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--)
2507 tree_cur -= ((rev_code >>= 1) & 1);
2508 if(!pTable->m_tree[-tree_cur - 1])
2510 pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next;
2511 tree_cur = tree_next;
2515 tree_cur = pTable->m_tree[-tree_cur - 1];
2517 tree_cur -= ((rev_code >>= 1) & 1);
2518 pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index;
2522 for(counter = 0; counter < (
r->m_table_sizes[0] +
r->m_table_sizes[1]);)
2528 r->m_len_codes[counter++] = (mz_uint8)dist;
2531 if((dist == 16) && (!counter))
2535 num_extra =
"\02\03\07"[dist - 16];
2537 s +=
"\03\03\013"[dist - 16];
2538 TINFL_MEMSET(
r->m_len_codes + counter, (dist == 16) ?
r->m_len_codes[counter - 1] : 0, s);
2541 if((
r->m_table_sizes[0] +
r->m_table_sizes[1]) != counter)
2545 TINFL_MEMCPY(
r->m_tables[0].m_code_size,
r->m_len_codes,
r->m_table_sizes[0]);
2546 TINFL_MEMCPY(
r->m_tables[1].m_code_size,
r->m_len_codes +
r->m_table_sizes[0],
r->m_table_sizes[1]);
2554 if(((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
2559 while(pOut_buf_cur >= pOut_buf_end)
2563 *pOut_buf_cur++ = (mz_uint8)counter;
2569#if TINFL_USE_64BIT_BITBUF
2572 bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits);
2579 bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits);
2584 if((sym2 =
r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
2585 code_len = sym2 >> 9;
2588 code_len = TINFL_FAST_LOOKUP_BITS;
2591 sym2 =
r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)];
2595 bit_buf >>= code_len;
2596 num_bits -= code_len;
2600#if !TINFL_USE_64BIT_BITBUF
2603 bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits);
2608 if((sym2 =
r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
2609 code_len = sym2 >> 9;
2612 code_len = TINFL_FAST_LOOKUP_BITS;
2615 sym2 =
r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)];
2618 bit_buf >>= code_len;
2619 num_bits -= code_len;
2621 pOut_buf_cur[0] = (mz_uint8)counter;
2628 pOut_buf_cur[1] = (mz_uint8)sym2;
2632 if((counter &= 511) == 256)
2635 num_extra = s_length_extra[counter - 257];
2636 counter = s_length_base[counter - 257];
2641 counter += extra_bits;
2645 num_extra = s_dist_extra[dist];
2646 dist = s_dist_base[dist];
2654 dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
2655 if((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
2660 pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
2662 if((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
2666 while(pOut_buf_cur >= pOut_buf_end)
2670 *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
2674#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
2675 else if((counter >= 9) && (counter <= dist))
2677 const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
2680 ((mz_uint32 *)pOut_buf_cur)[0] = ((
const mz_uint32 *)pSrc)[0];
2681 ((mz_uint32 *)pOut_buf_cur)[1] = ((
const mz_uint32 *)pSrc)[1];
2683 }
while((pSrc += 8) < pSrc_end);
2684 if((counter &= 7) < 3)
2688 pOut_buf_cur[0] = pSrc[0];
2690 pOut_buf_cur[1] = pSrc[1];
2691 pOut_buf_cur += counter;
2699 pOut_buf_cur[0] = pSrc[0];
2700 pOut_buf_cur[1] = pSrc[1];
2701 pOut_buf_cur[2] = pSrc[2];
2704 }
while((
int)(counter -= 3) > 2);
2705 if((
int)counter > 0)
2707 pOut_buf_cur[0] = pSrc[0];
2708 if((
int)counter > 1)
2709 pOut_buf_cur[1] = pSrc[1];
2710 pOut_buf_cur += counter;
2714 }
while(!(
r->m_final & 1));
2719 while((pIn_buf_cur > pIn_buf_next) && (num_bits >= 8))
2724 bit_buf &= (tinfl_bit_buf_t)((1ULL << num_bits) - 1ULL);
2725 MZ_ASSERT(!num_bits);
2727 if(decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
2729 for(counter = 0; counter < 4; ++counter)
2736 r->m_z_adler32 = (
r->m_z_adler32 << 8) | s;
2747 if((status != TINFL_STATUS_NEEDS_MORE_INPUT) && (status != TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS))
2749 while((pIn_buf_cur > pIn_buf_next) && (num_bits >= 8))
2755 r->m_num_bits = num_bits;
2756 r->m_bit_buf = bit_buf & (tinfl_bit_buf_t)((1ULL << num_bits) - 1ULL);
2758 r->m_counter = counter;
2759 r->m_num_extra = num_extra;
2760 r->m_dist_from_out_buf_start = dist_from_out_buf_start;
2761 *pIn_buf_size = pIn_buf_cur - pIn_buf_next;
2762 *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
2763 if((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0))
2765 const mz_uint8 *ptr = pOut_buf_next;
2766 size_t buf_len = *pOut_buf_size;
2767 mz_uint32 i,
s1 =
r->m_check_adler32 & 0xffff,
s2 =
r->m_check_adler32 >> 16;
2768 size_t block_len = buf_len % 5552;
2771 for(i = 0; i + 7 < block_len; i += 8, ptr += 8)
2782 for(; i < block_len; ++i)
2784 s1 %= 65521U,
s2 %= 65521U;
2785 buf_len -= block_len;
2788 r->m_check_adler32 = (
s2 << 16) +
s1;
2789 if((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (
r->m_check_adler32 !=
r->m_z_adler32))
2790 status = TINFL_STATUS_ADLER32_MISMATCH;
2798 tinfl_decompressor decomp;
2799 void *pBuf = NULL, *pNew_buf;
2800 size_t src_buf_ofs = 0, out_buf_capacity = 0;
2802 tinfl_init(&decomp);
2805 size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
2806 tinfl_status status =
tinfl_decompress(&decomp, (
const mz_uint8 *)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8 *)pBuf, pBuf ? (mz_uint8 *)pBuf + *pOut_len : NULL, &dst_buf_size,
2807 (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
2808 if((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT))
2814 src_buf_ofs += src_buf_size;
2815 *pOut_len += dst_buf_size;
2816 if(status == TINFL_STATUS_DONE)
2818 new_out_buf_capacity = out_buf_capacity * 2;
2819 if(new_out_buf_capacity < 128)
2820 new_out_buf_capacity = 128;
2821 pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity);
2829 out_buf_capacity = new_out_buf_capacity;
2836 tinfl_decompressor decomp;
2837 tinfl_status status;
2838 tinfl_init(&decomp);
2839 status =
tinfl_decompress(&decomp, (
const mz_uint8 *)pSrc_buf, &src_buf_len, (mz_uint8 *)pOut_buf, (mz_uint8 *)pOut_buf, &out_buf_len, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
2840 return (status != TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len;
2846 tinfl_decompressor decomp;
2847 mz_uint8 *pDict = (mz_uint8 *)MZ_MALLOC(TINFL_LZ_DICT_SIZE);
2848 size_t in_buf_ofs = 0, dict_ofs = 0;
2850 return TINFL_STATUS_FAILED;
2851 tinfl_init(&decomp);
2854 size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs;
2855 tinfl_status status =
tinfl_decompress(&decomp, (
const mz_uint8 *)pIn_buf + in_buf_ofs, &in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size,
2856 (flags & ~(TINFL_FLAG_HAS_MORE_INPUT | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)));
2857 in_buf_ofs += in_buf_size;
2858 if((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (
int)dst_buf_size, pPut_buf_user)))
2860 if(status != TINFL_STATUS_HAS_MORE_OUTPUT)
2862 result = (status == TINFL_STATUS_DONE);
2865 dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1);
2868 *pIn_buf_size = in_buf_ofs;
2874 tinfl_decompressor *pDecomp = (tinfl_decompressor *)MZ_MALLOC(
sizeof(tinfl_decompressor));
2876 tinfl_init(pDecomp);
2922#ifdef MINIZ_NO_STDIO
2923#define MZ_FILE void *
2925#include <sys/stat.h>
2927#if defined(_MSC_VER) || defined(__MINGW64__)
2928static FILE *mz_fopen(
const char *pFilename,
const char *pMode)
2931 fopen_s(&pFile, pFilename, pMode);
2934static FILE *mz_freopen(
const char *pPath,
const char *pMode, FILE *pStream)
2937 if(freopen_s(&pFile, pPath, pMode, pStream))
2941#ifndef MINIZ_NO_TIME
2942#include <sys/utime.h>
2944#define MZ_FOPEN mz_fopen
2945#define MZ_FCLOSE fclose
2946#define MZ_FREAD fread
2947#define MZ_FWRITE fwrite
2948#define MZ_FTELL64 _ftelli64
2949#define MZ_FSEEK64 _fseeki64
2950#define MZ_FILE_STAT_STRUCT _stat
2951#define MZ_FILE_STAT _stat
2952#define MZ_FFLUSH fflush
2953#define MZ_FREOPEN mz_freopen
2954#define MZ_DELETE_FILE remove
2955#elif defined(__MINGW32__)
2956#ifndef MINIZ_NO_TIME
2957#include <sys/utime.h>
2959#define MZ_FOPEN(f, m) fopen(f, m)
2960#define MZ_FCLOSE fclose
2961#define MZ_FREAD fread
2962#define MZ_FWRITE fwrite
2963#define MZ_FTELL64 ftello64
2964#define MZ_FSEEK64 fseeko64
2965#define MZ_FILE_STAT_STRUCT _stat
2966#define MZ_FILE_STAT _stat
2967#define MZ_FFLUSH fflush
2968#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
2969#define MZ_DELETE_FILE remove
2970#elif defined(__TINYC__)
2971#ifndef MINIZ_NO_TIME
2972#include <sys/utime.h>
2974#define MZ_FOPEN(f, m) fopen(f, m)
2975#define MZ_FCLOSE fclose
2976#define MZ_FREAD fread
2977#define MZ_FWRITE fwrite
2978#define MZ_FTELL64 ftell
2979#define MZ_FSEEK64 fseek
2980#define MZ_FILE_STAT_STRUCT stat
2981#define MZ_FILE_STAT stat
2982#define MZ_FFLUSH fflush
2983#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
2984#define MZ_DELETE_FILE remove
2985#elif defined(__GNUC__) && _LARGEFILE64_SOURCE
2986#ifndef MINIZ_NO_TIME
2989#define MZ_FOPEN(f, m) fopen64(f, m)
2990#define MZ_FCLOSE fclose
2991#define MZ_FREAD fread
2992#define MZ_FWRITE fwrite
2993#define MZ_FTELL64 ftello64
2994#define MZ_FSEEK64 fseeko64
2995#define MZ_FILE_STAT_STRUCT stat64
2996#define MZ_FILE_STAT stat64
2997#define MZ_FFLUSH fflush
2998#define MZ_FREOPEN(p, m, s) freopen64(p, m, s)
2999#define MZ_DELETE_FILE remove
3000#elif defined(__APPLE__) && _LARGEFILE64_SOURCE
3001#ifndef MINIZ_NO_TIME
3004#define MZ_FOPEN(f, m) fopen(f, m)
3005#define MZ_FCLOSE fclose
3006#define MZ_FREAD fread
3007#define MZ_FWRITE fwrite
3008#define MZ_FTELL64 ftello
3009#define MZ_FSEEK64 fseeko
3010#define MZ_FILE_STAT_STRUCT stat
3011#define MZ_FILE_STAT stat
3012#define MZ_FFLUSH fflush
3013#define MZ_FREOPEN(p, m, s) freopen(p, m, s)
3014#define MZ_DELETE_FILE remove
3017#pragma message("Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.")
3018#ifndef MINIZ_NO_TIME
3021#define MZ_FOPEN(f, m) fopen(f, m)
3022#define MZ_FCLOSE fclose
3023#define MZ_FREAD fread
3024#define MZ_FWRITE fwrite
3025#define MZ_FTELL64 ftello
3026#define MZ_FSEEK64 fseeko
3027#define MZ_FILE_STAT_STRUCT stat
3028#define MZ_FILE_STAT stat
3029#define MZ_FFLUSH fflush
3030#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
3031#define MZ_DELETE_FILE remove
3035#define MZ_TOLOWER(c) ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c))
3158#define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size) (array_ptr)->m_element_size = element_size
3160#if defined(DEBUG) || defined(_DEBUG) || defined(NDEBUG)
3161static MZ_FORCEINLINE mz_uint mz_zip_array_range_check(
const mz_zip_array *pArray, mz_uint index)
3163 MZ_ASSERT(index < pArray->m_size);
3166#define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[mz_zip_array_range_check(array_ptr, index)]
3168#define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[index]
3179 pZip->m_pFree(pZip->m_pAlloc_opaque, pArray->
m_p);
3186 size_t new_capacity = min_new_capacity;
3192 new_capacity = MZ_MAX(1, pArray->
m_capacity);
3193 while(new_capacity < min_new_capacity)
3196 if(NULL == (pNew_p = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pArray->
m_p, pArray->
m_element_size, new_capacity)))
3198 pArray->
m_p = pNew_p;
3220 pArray->
m_size = new_size;
3231 size_t orig_size = pArray->
m_size;
3238#ifndef MINIZ_NO_TIME
3242 memset(&tm, 0,
sizeof(tm));
3244 tm.tm_year = ((dos_date >> 9) & 127) + 1980 - 1900;
3245 tm.tm_mon = ((dos_date >> 5) & 15) - 1;
3246 tm.tm_mday = dos_date & 31;
3247 tm.tm_hour = (dos_time >> 11) & 31;
3248 tm.tm_min = (dos_time >> 5) & 63;
3249 tm.tm_sec = (dos_time << 1) & 62;
3256 struct tm tm_struct;
3257 struct tm *tm = &tm_struct;
3258 errno_t err = localtime_s(tm, &time);
3266 struct tm *tm = localtime(&time);
3269 *pDOS_time = (mz_uint16)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) + ((tm->tm_sec) >> 1));
3270 *pDOS_date = (mz_uint16)(((tm->tm_year + 1900 - 1980) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday);
3273#ifndef MINIZ_NO_STDIO
3282 *pTime = file_stat.st_mtime;
3291 memset(&t, 0,
sizeof(t));
3292 t.actime = access_time;
3293 t.modtime = modified_time;
3295 return !utime(pFilename, &t);
3303 pZip->m_last_error = err_num;
3310 if((!pZip) || (pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID))
3317 if(!pZip->m_pRealloc)
3320 pZip->m_archive_size = 0;
3321 pZip->m_central_directory_file_ofs = 0;
3322 pZip->m_total_files = 0;
3323 pZip->m_last_error = MZ_ZIP_NO_ERROR;
3325 if(NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1,
sizeof(mz_zip_internal_state))))
3328 memset(pZip->m_pState, 0,
sizeof(mz_zip_internal_state));
3332 pZip->m_pState->m_init_flags = flags;
3333 pZip->m_pState->m_zip64 = MZ_FALSE;
3334 pZip->m_pState->m_zip64_has_extended_info_fields = MZ_FALSE;
3336 pZip->m_zip_mode = MZ_ZIP_MODE_READING;
3346 mz_uint8 l = 0,
r = 0;
3349 pE = pL + MZ_MIN(l_len, r_len);
3357 return (pL == pE) ? (l_len < r_len) : (l <
r);
3360#define MZ_SWAP_UINT32(a, b) \
3372 mz_zip_internal_state *pState = pZip->m_pState;
3373 const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets;
3374 const mz_zip_array *pCentral_dir = &pState->m_central_dir;
3375 mz_uint32 *pIndices;
3376 mz_uint32 start, end;
3377 const mz_uint32 size = pZip->m_total_files;
3384 start = (size - 2U) >> 1U;
3387 mz_uint64 child, root = start;
3390 if((child = (root << 1U) + 1U) >= size)
3392 child += (((child + 1U) < size) && (
mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1U])));
3406 mz_uint64 child, root = 0;
3410 if((child = (root << 1U) + 1U) >= end)
3412 child += (((child + 1U) < end) &&
mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1U]));
3424 mz_int64 cur_file_ofs;
3425 mz_uint32 buf_u32[4096 /
sizeof(mz_uint32)];
3426 mz_uint8 *pBuf = (mz_uint8 *)buf_u32;
3429 if(pZip->m_archive_size < record_size)
3433 cur_file_ofs = MZ_MAX((mz_int64)pZip->m_archive_size - (mz_int64)
sizeof(buf_u32), 0);
3436 int i, n = (int)MZ_MIN(
sizeof(buf_u32), pZip->m_archive_size - cur_file_ofs);
3438 if(pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, n) != (mz_uint)n)
3441 for(i = n - 4; i >= 0; --i)
3443 mz_uint s = MZ_READ_LE32(pBuf + i);
3446 if((pZip->m_archive_size - (cur_file_ofs + i)) >= record_size)
3458 if((!cur_file_ofs) || ((pZip->m_archive_size - cur_file_ofs) >= (MZ_UINT16_MAX + record_size)))
3461 cur_file_ofs = MZ_MAX(cur_file_ofs - (
sizeof(buf_u32) - 3), 0);
3464 *pOfs = cur_file_ofs;
3470 mz_uint cdir_size = 0, cdir_entries_on_this_disk = 0, num_this_disk = 0, cdir_disk_index = 0;
3471 mz_uint64 cdir_ofs = 0;
3472 mz_int64 cur_file_ofs = 0;
3475 mz_uint32 buf_u32[4096 /
sizeof(mz_uint32)];
3476 mz_uint8 *pBuf = (mz_uint8 *)buf_u32;
3477 mz_bool sort_central_dir = ((flags & MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY) == 0);
3479 mz_uint8 *pZip64_locator = (mz_uint8 *)zip64_end_of_central_dir_locator_u32;
3482 mz_uint8 *pZip64_end_of_central_dir = (mz_uint8 *)zip64_end_of_central_dir_header_u32;
3484 mz_uint64 zip64_end_of_central_dir_ofs = 0;
3514 pZip->m_pState->m_zip64 = MZ_TRUE;
3528 if(pZip->m_pState->m_zip64)
3539 if(zip64_total_num_of_disks != 1U)
3543 if(zip64_cdir_total_entries > MZ_UINT32_MAX)
3546 pZip->m_total_files = (mz_uint32)zip64_cdir_total_entries;
3548 if(zip64_cdir_total_entries_on_this_disk > MZ_UINT32_MAX)
3551 cdir_entries_on_this_disk = (mz_uint32)zip64_cdir_total_entries_on_this_disk;
3554 if(zip64_size_of_central_directory > MZ_UINT32_MAX)
3557 cdir_size = (mz_uint32)zip64_size_of_central_directory;
3566 if(pZip->m_total_files != cdir_entries_on_this_disk)
3569 if(((num_this_disk | cdir_disk_index) != 0) && ((num_this_disk != 1) || (cdir_disk_index != 1)))
3575 if((cdir_ofs + (mz_uint64)cdir_size) > pZip->m_archive_size)
3578 pZip->m_central_directory_file_ofs = cdir_ofs;
3580 if(pZip->m_total_files)
3585 (!
mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir_offsets, pZip->m_total_files, MZ_FALSE)))
3588 if(sort_central_dir)
3590 if(!
mz_zip_array_resize(pZip, &pZip->m_pState->m_sorted_central_dir_offsets, pZip->m_total_files, MZ_FALSE))
3594 if(pZip->m_pRead(pZip->m_pIO_opaque, cdir_ofs, pZip->m_pState->m_central_dir.m_p, cdir_size) != cdir_size)
3598 p = (
const mz_uint8 *)pZip->m_pState->m_central_dir.m_p;
3599 for(n = cdir_size, i = 0; i < pZip->m_total_files; ++i)
3601 mz_uint total_header_size, disk_index, bit_flags, filename_size, ext_data_size;
3602 mz_uint64 comp_size, decomp_size, local_header_ofs;
3607 MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, i) = (mz_uint32)(p - (
const mz_uint8 *)pZip->m_pState->m_central_dir.m_p);
3609 if(sort_central_dir)
3618 if((!pZip->m_pState->m_zip64_has_extended_info_fields) &&
3620 (MZ_MAX(MZ_MAX(comp_size, decomp_size), local_header_ofs) == MZ_UINT32_MAX))
3623 mz_uint32 extra_size_remaining = ext_data_size;
3625 if(extra_size_remaining)
3631 if(extra_size_remaining < (
sizeof(mz_uint16) * 2))
3634 mz_uint32 field_id = MZ_READ_LE16(pExtra_data);
3635 mz_uint32 field_data_size = MZ_READ_LE16(pExtra_data +
sizeof(mz_uint16));
3637 if((field_data_size +
sizeof(mz_uint16) * 2) > extra_size_remaining)
3643 pZip->m_pState->m_zip64 = MZ_TRUE;
3644 pZip->m_pState->m_zip64_has_extended_info_fields = MZ_TRUE;
3648 pExtra_data +=
sizeof(mz_uint16) * 2 + field_data_size;
3649 extra_size_remaining = extra_size_remaining -
sizeof(mz_uint16) * 2 - field_data_size;
3650 }
while(extra_size_remaining);
3655 if((comp_size != MZ_UINT32_MAX) && (decomp_size != MZ_UINT32_MAX))
3657 if(((!MZ_READ_LE32(p +
MZ_ZIP_CDH_METHOD_OFS)) && (decomp_size != comp_size)) || (decomp_size && !comp_size))
3662 if((disk_index == MZ_UINT16_MAX) || ((disk_index != num_this_disk) && (disk_index != 1)))
3665 if(comp_size != MZ_UINT32_MAX)
3678 n -= total_header_size;
3679 p += total_header_size;
3683 if(sort_central_dir)
3692 MZ_CLEAR_OBJ(*pZip);
3697 mz_bool status = MZ_TRUE;
3702 if((!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
3705 pZip->m_last_error = MZ_ZIP_INVALID_PARAMETER;
3712 mz_zip_internal_state *pState = pZip->m_pState;
3713 pZip->m_pState = NULL;
3719#ifndef MINIZ_NO_STDIO
3722 if(pZip->m_zip_type == MZ_ZIP_TYPE_FILE)
3727 pZip->m_last_error = MZ_ZIP_FILE_CLOSE_FAILED;
3731 pState->m_pFile = NULL;
3735 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
3737 pZip->m_zip_mode = MZ_ZIP_MODE_INVALID;
3748 if((!pZip) || (!pZip->m_pRead))
3754 pZip->m_zip_type = MZ_ZIP_TYPE_USER;
3755 pZip->m_archive_size = size;
3768 mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
3769 size_t s = (file_ofs >= pZip->m_archive_size) ? 0 : (size_t)MZ_MIN(pZip->m_archive_size - file_ofs, n);
3770 memcpy(pBuf, (
const mz_uint8 *)pZip->m_pState->m_pMem + file_ofs, s);
3785 pZip->m_zip_type = MZ_ZIP_TYPE_MEMORY;
3786 pZip->m_archive_size = size;
3788 pZip->m_pIO_opaque = pZip;
3791 pZip->m_pState->m_pMem =
const_cast<void *
>(pMem);
3793 pZip->m_pState->m_pMem = (
void *)pMem;
3796 pZip->m_pState->m_mem_size = size;
3807#ifndef MINIZ_NO_STDIO
3810 mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
3811 mz_int64 cur_ofs =
MZ_FTELL64(pZip->m_pState->m_pFile);
3813 file_ofs += pZip->m_pState->m_file_archive_start_ofs;
3815 if(((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (
MZ_FSEEK64(pZip->m_pState->m_pFile, (mz_int64)file_ofs, SEEK_SET))))
3818 return MZ_FREAD(pBuf, 1, n, pZip->m_pState->m_pFile);
3831 mz_uint64 file_size;
3832 MZ_FILE *pFile =
MZ_FOPEN(pFilename,
"rb");
3836 file_size = archive_size;
3859 pZip->m_zip_type = MZ_ZIP_TYPE_FILE;
3861 pZip->m_pIO_opaque = pZip;
3862 pZip->m_pState->m_pFile = pFile;
3863 pZip->m_archive_size = file_size;
3864 pZip->m_pState->m_file_archive_start_ofs = file_start_ofs;
3877 mz_uint64 cur_file_ofs;
3879 if((!pZip) || (!pFile))
3889 archive_size =
MZ_FTELL64(pFile) - cur_file_ofs;
3898 pZip->m_zip_type = MZ_ZIP_TYPE_CFILE;
3901 pZip->m_pIO_opaque = pZip;
3902 pZip->m_pState->m_pFile = pFile;
3903 pZip->m_archive_size = archive_size;
3904 pZip->m_pState->m_file_archive_start_ofs = cur_file_ofs;
3917static MZ_FORCEINLINE
const mz_uint8 *
mz_zip_get_cdh(mz_zip_archive *pZip, mz_uint file_index)
3919 if((!pZip) || (!pZip->m_pState) || (file_index >= pZip->m_total_files))
3976 mz_uint filename_len, attribute_mapping_id, external_attr;
3995 (void)attribute_mapping_id;
4006static mz_bool
mz_zip_file_stat_internal(mz_zip_archive *pZip, mz_uint file_index,
const mz_uint8 *pCentral_dir_header, mz_zip_archive_file_stat *pStat, mz_bool *pFound_zip64_extra_data)
4009 const mz_uint8 *p = pCentral_dir_header;
4011 if(pFound_zip64_extra_data)
4012 *pFound_zip64_extra_data = MZ_FALSE;
4014 if((!p) || (!pStat))
4018 pStat->m_file_index = file_index;
4019 pStat->m_central_dir_ofs =
MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index);
4024#ifndef MINIZ_NO_TIME
4036 n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE - 1);
4038 pStat->m_filename[n] =
'\0';
4041 n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE - 1);
4042 pStat->m_comment_size = n;
4044 pStat->m_comment[n] =
'\0';
4053 if(MZ_MAX(MZ_MAX(pStat->m_comp_size, pStat->m_uncomp_size), pStat->m_local_header_ofs) == MZ_UINT32_MAX)
4058 if(extra_size_remaining)
4064 if(extra_size_remaining < (
sizeof(mz_uint16) * 2))
4067 mz_uint32 field_id = MZ_READ_LE16(pExtra_data);
4068 mz_uint32 field_data_size = MZ_READ_LE16(pExtra_data +
sizeof(mz_uint16));
4070 if((field_data_size +
sizeof(mz_uint16) * 2) > extra_size_remaining)
4075 const mz_uint8 *pField_data = pExtra_data +
sizeof(mz_uint16) * 2;
4076 mz_uint32 field_data_remaining = field_data_size;
4078 if(pFound_zip64_extra_data)
4079 *pFound_zip64_extra_data = MZ_TRUE;
4081 if(pStat->m_uncomp_size == MZ_UINT32_MAX)
4083 if(field_data_remaining <
sizeof(mz_uint64))
4086 pStat->m_uncomp_size = MZ_READ_LE64(pField_data);
4087 pField_data +=
sizeof(mz_uint64);
4088 field_data_remaining -=
sizeof(mz_uint64);
4091 if(pStat->m_comp_size == MZ_UINT32_MAX)
4093 if(field_data_remaining <
sizeof(mz_uint64))
4096 pStat->m_comp_size = MZ_READ_LE64(pField_data);
4097 pField_data +=
sizeof(mz_uint64);
4098 field_data_remaining -=
sizeof(mz_uint64);
4101 if(pStat->m_local_header_ofs == MZ_UINT32_MAX)
4103 if(field_data_remaining <
sizeof(mz_uint64))
4106 pStat->m_local_header_ofs = MZ_READ_LE64(pField_data);
4107 pField_data +=
sizeof(mz_uint64);
4108 field_data_remaining -=
sizeof(mz_uint64);
4114 pExtra_data +=
sizeof(mz_uint16) * 2 + field_data_size;
4115 extra_size_remaining = extra_size_remaining -
sizeof(mz_uint16) * 2 - field_data_size;
4116 }
while(extra_size_remaining);
4126 if(flags & MZ_ZIP_FLAG_CASE_SENSITIVE)
4127 return 0 == memcmp(pA, pB, len);
4128 for(i = 0; i < len; ++i)
4138 mz_uint8 l = 0,
r = 0;
4140 pE = pL + MZ_MIN(l_len, r_len);
4148 return (pL == pE) ? (int)(l_len - r_len) : (l -
r);
4153 mz_zip_internal_state *pState = pZip->m_pState;
4154 const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets;
4155 const mz_zip_array *pCentral_dir = &pState->m_central_dir;
4156 mz_uint32 *pIndices = &
MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0);
4157 const uint32_t size = pZip->m_total_files;
4158 const mz_uint filename_len = (mz_uint)strlen(pFilename);
4167 mz_int64 l = 0, h = (mz_int64)size - 1;
4171 mz_int64 m = l + ((h - l) >> 1);
4172 uint32_t file_index = pIndices[(uint32_t)m];
4178 *pIndex = file_index;
4203 size_t name_len, comment_len;
4208 if((!pZip) || (!pZip->m_pState) || (!pName))
4212 if(((pZip->m_pState->m_init_flags & MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY) == 0) &&
4213 (pZip->m_zip_mode == MZ_ZIP_MODE_READING) &&
4214 ((flags & (MZ_ZIP_FLAG_IGNORE_PATH | MZ_ZIP_FLAG_CASE_SENSITIVE)) == 0) && (!pComment) && (pZip->m_pState->m_sorted_central_dir_offsets.m_size))
4220 name_len = strlen(pName);
4221 if(name_len > MZ_UINT16_MAX)
4224 comment_len = pComment ? strlen(pComment) : 0;
4225 if(comment_len > MZ_UINT16_MAX)
4228 for(file_index = 0; file_index < pZip->m_total_files; file_index++)
4233 if(filename_len < name_len)
4238 const char *pFile_comment = pFilename + filename_len + file_extra_len;
4239 if((file_comment_len != comment_len) || (!
mz_zip_string_equal(pComment, pFile_comment, file_comment_len, flags)))
4242 if((flags & MZ_ZIP_FLAG_IGNORE_PATH) && (filename_len))
4244 int ofs = filename_len - 1;
4247 if((pFilename[ofs] ==
'/') || (pFilename[ofs] ==
'\\') || (pFilename[ofs] ==
':'))
4249 }
while(--ofs >= 0);
4252 filename_len -= ofs;
4254 if((filename_len == name_len) && (
mz_zip_string_equal(pName, pFilename, filename_len, flags)))
4257 *pIndex = file_index;
4267 int status = TINFL_STATUS_DONE;
4268 mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail;
4269 mz_zip_archive_file_stat file_stat;
4272 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
4273 tinfl_decompressor inflator;
4275 if((!pZip) || (!pZip->m_pState) || ((buf_size) && (!pBuf)) || ((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead))
4282 if((file_stat.m_is_directory) || (!file_stat.m_comp_size))
4290 if((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method !=
MZ_DEFLATED))
4294 needed_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? file_stat.m_comp_size : file_stat.m_uncomp_size;
4295 if(buf_size < needed_size)
4299 cur_file_ofs = file_stat.m_local_header_ofs;
4307 if((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size)
4310 if((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method))
4313 if(pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, (
size_t)needed_size) != needed_size)
4316#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4317 if((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) == 0)
4319 if(
mz_crc32(
MZ_CRC32_INIT, (
const mz_uint8 *)pBuf, (
size_t)file_stat.m_uncomp_size) != file_stat.m_crc32)
4328 tinfl_init(&inflator);
4330 if(pZip->m_pState->m_pMem)
4333 pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs;
4334 read_buf_size = read_buf_avail = file_stat.m_comp_size;
4337 else if(pUser_read_buf)
4340 if(!user_read_buf_size)
4342 pRead_buf = (mz_uint8 *)pUser_read_buf;
4343 read_buf_size = user_read_buf_size;
4345 comp_remaining = file_stat.m_comp_size;
4350 read_buf_size = MZ_MIN(file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
4351 if(((
sizeof(
size_t) ==
sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF))
4354 if(NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (
size_t)read_buf_size)))
4358 comp_remaining = file_stat.m_comp_size;
4364 size_t in_buf_size, out_buf_size = (size_t)(file_stat.m_uncomp_size - out_buf_ofs);
4365 if((!read_buf_avail) && (!pZip->m_pState->m_pMem))
4367 read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
4368 if(pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
4370 status = TINFL_STATUS_FAILED;
4374 cur_file_ofs += read_buf_avail;
4375 comp_remaining -= read_buf_avail;
4378 in_buf_size = (size_t)read_buf_avail;
4379 status =
tinfl_decompress(&inflator, (mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pBuf, (mz_uint8 *)pBuf + out_buf_ofs, &out_buf_size, TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF | (comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0));
4380 read_buf_avail -= in_buf_size;
4381 read_buf_ofs += in_buf_size;
4382 out_buf_ofs += out_buf_size;
4383 }
while(status == TINFL_STATUS_NEEDS_MORE_INPUT);
4385 if(status == TINFL_STATUS_DONE)
4388 if(out_buf_ofs != file_stat.m_uncomp_size)
4391 status = TINFL_STATUS_FAILED;
4393#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4394 else if(
mz_crc32(
MZ_CRC32_INIT, (
const mz_uint8 *)pBuf, (
size_t)file_stat.m_uncomp_size) != file_stat.m_crc32)
4397 status = TINFL_STATUS_FAILED;
4402 if((!pZip->m_pState->m_pMem) && (!pUser_read_buf))
4403 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
4405 return status == TINFL_STATUS_DONE;
4410 mz_uint32 file_index;
4428 mz_uint64 comp_size, uncomp_size, alloc_size;
4444 alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size;
4445 if(((
sizeof(
size_t) ==
sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF))
4451 if(NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (
size_t)alloc_size)))
4459 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
4464 *pSize = (size_t)alloc_size;
4470 mz_uint32 file_index;
4482 int status = TINFL_STATUS_DONE;
4484 mz_uint64 read_buf_size, read_buf_ofs = 0, read_buf_avail, comp_remaining, out_buf_ofs = 0, cur_file_ofs;
4485 mz_zip_archive_file_stat file_stat;
4486 void *pRead_buf = NULL;
4487 void *pWrite_buf = NULL;
4489 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
4491 if((!pZip) || (!pZip->m_pState) || (!pCallback) || (!pZip->m_pRead))
4498 if((file_stat.m_is_directory) || (!file_stat.m_comp_size))
4506 if((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method !=
MZ_DEFLATED))
4510 cur_file_ofs = file_stat.m_local_header_ofs;
4518 if((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size)
4522 if(pZip->m_pState->m_pMem)
4524 pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs;
4525 read_buf_size = read_buf_avail = file_stat.m_comp_size;
4530 read_buf_size = MZ_MIN(file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
4531 if(NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (
size_t)read_buf_size)))
4535 comp_remaining = file_stat.m_comp_size;
4538 if((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method))
4541 if(pZip->m_pState->m_pMem)
4543 if(((
sizeof(
size_t) ==
sizeof(mz_uint32))) && (file_stat.m_comp_size > MZ_UINT32_MAX))
4546 if(pCallback(pOpaque, out_buf_ofs, pRead_buf, (
size_t)file_stat.m_comp_size) != file_stat.m_comp_size)
4549 status = TINFL_STATUS_FAILED;
4551 else if(!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
4553#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4554 file_crc32 = (mz_uint32)
mz_crc32(file_crc32, (
const mz_uint8 *)pRead_buf, (
size_t)file_stat.m_comp_size);
4558 cur_file_ofs += file_stat.m_comp_size;
4559 out_buf_ofs += file_stat.m_comp_size;
4564 while(comp_remaining)
4566 read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
4567 if(pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
4570 status = TINFL_STATUS_FAILED;
4574#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4575 if(!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
4577 file_crc32 = (mz_uint32)
mz_crc32(file_crc32, (
const mz_uint8 *)pRead_buf, (
size_t)read_buf_avail);
4581 if(pCallback(pOpaque, out_buf_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
4584 status = TINFL_STATUS_FAILED;
4588 cur_file_ofs += read_buf_avail;
4589 out_buf_ofs += read_buf_avail;
4590 comp_remaining -= read_buf_avail;
4596 tinfl_decompressor inflator;
4597 tinfl_init(&inflator);
4599 if(NULL == (pWrite_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, TINFL_LZ_DICT_SIZE)))
4602 status = TINFL_STATUS_FAILED;
4608 mz_uint8 *pWrite_buf_cur = (mz_uint8 *)pWrite_buf + (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
4609 size_t in_buf_size, out_buf_size = TINFL_LZ_DICT_SIZE - (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
4610 if((!read_buf_avail) && (!pZip->m_pState->m_pMem))
4612 read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
4613 if(pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
4616 status = TINFL_STATUS_FAILED;
4619 cur_file_ofs += read_buf_avail;
4620 comp_remaining -= read_buf_avail;
4624 in_buf_size = (size_t)read_buf_avail;
4625 status =
tinfl_decompress(&inflator, (
const mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pWrite_buf, pWrite_buf_cur, &out_buf_size, comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0);
4626 read_buf_avail -= in_buf_size;
4627 read_buf_ofs += in_buf_size;
4631 if(pCallback(pOpaque, out_buf_ofs, pWrite_buf_cur, out_buf_size) != out_buf_size)
4634 status = TINFL_STATUS_FAILED;
4638#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4639 file_crc32 = (mz_uint32)
mz_crc32(file_crc32, pWrite_buf_cur, out_buf_size);
4641 if((out_buf_ofs += out_buf_size) > file_stat.m_uncomp_size)
4644 status = TINFL_STATUS_FAILED;
4648 }
while((status == TINFL_STATUS_NEEDS_MORE_INPUT) || (status == TINFL_STATUS_HAS_MORE_OUTPUT));
4652 if((status == TINFL_STATUS_DONE) && (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)))
4655 if(out_buf_ofs != file_stat.m_uncomp_size)
4658 status = TINFL_STATUS_FAILED;
4660#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4661 else if(file_crc32 != file_stat.m_crc32)
4664 status = TINFL_STATUS_FAILED;
4669 if(!pZip->m_pState->m_pMem)
4670 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
4673 pZip->m_pFree(pZip->m_pAlloc_opaque, pWrite_buf);
4675 return status == TINFL_STATUS_DONE;
4680 mz_uint32 file_index;
4687#ifndef MINIZ_NO_STDIO
4692 return MZ_FWRITE(pBuf, 1, n, (MZ_FILE *)pOpaque);
4698 mz_zip_archive_file_stat file_stat;
4704 if((file_stat.m_is_directory) || (!file_stat.m_is_supported))
4707 pFile =
MZ_FOPEN(pDst_filename,
"wb");
4721#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_STDIO)
4731 mz_uint32 file_index;
4740 mz_zip_archive_file_stat file_stat;
4745 if((file_stat.m_is_directory) || (!file_stat.m_is_supported))
4753 mz_uint32 file_index;
4763 mz_uint32 *p = (mz_uint32 *)pOpaque;
4765 *p = (mz_uint32)
mz_crc32(*p, (
const mz_uint8 *)pBuf, n);
4771 mz_zip_archive_file_stat file_stat;
4772 mz_zip_internal_state *pState;
4773 const mz_uint8 *pCentral_dir_header;
4774 mz_bool found_zip64_ext_data_in_cdir = MZ_FALSE;
4775 mz_bool found_zip64_ext_data_in_ldir = MZ_FALSE;
4777 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
4778 mz_uint64 local_header_ofs = 0;
4779 mz_uint32 local_header_filename_len, local_header_extra_len, local_header_crc32;
4780 mz_uint64 local_header_comp_size, local_header_uncomp_size;
4782 mz_bool has_data_descriptor;
4783 mz_uint32 local_header_bit_flags;
4788 if((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (!pZip->m_pRead))
4791 if(file_index > pZip->m_total_files)
4794 pState = pZip->m_pState;
4802 if((file_stat.m_is_directory) || (!file_stat.m_uncomp_size))
4806 if(file_stat.m_is_encrypted)
4810 if((file_stat.m_method != 0) && (file_stat.m_method !=
MZ_DEFLATED))
4813 if(!file_stat.m_is_supported)
4817 local_header_ofs = file_stat.m_local_header_ofs;
4830 has_data_descriptor = (local_header_bit_flags & 8) != 0;
4832 if(local_header_filename_len != strlen(file_stat.m_filename))
4835 if((local_header_ofs +
MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_len + local_header_extra_len + file_stat.m_comp_size) > pZip->m_archive_size)
4838 if(!
mz_zip_array_resize(pZip, &file_data_array, MZ_MAX(local_header_filename_len, local_header_extra_len), MZ_FALSE))
4841 if(local_header_filename_len)
4843 if(pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs +
MZ_ZIP_LOCAL_DIR_HEADER_SIZE, file_data_array.
m_p, local_header_filename_len) != local_header_filename_len)
4846 goto handle_failure;
4850 if(memcmp(file_stat.m_filename, file_data_array.
m_p, local_header_filename_len) != 0)
4853 goto handle_failure;
4857 if((local_header_extra_len) && ((local_header_comp_size == MZ_UINT32_MAX) || (local_header_uncomp_size == MZ_UINT32_MAX)))
4859 if(pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs +
MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_len, file_data_array.
m_p, local_header_extra_len) != local_header_extra_len)
4862 goto handle_failure;
4865 mz_uint32 extra_size_remaining = local_header_extra_len;
4866 const mz_uint8 *pExtra_data = (
const mz_uint8 *)file_data_array.
m_p;
4870 mz_uint32 field_id, field_data_size, field_total_size;
4872 if(extra_size_remaining < (
sizeof(mz_uint16) * 2))
4875 field_id = MZ_READ_LE16(pExtra_data);
4876 field_data_size = MZ_READ_LE16(pExtra_data +
sizeof(mz_uint16));
4877 field_total_size = field_data_size +
sizeof(mz_uint16) * 2;
4879 if(field_total_size > extra_size_remaining)
4884 const mz_uint8 *pSrc_field_data = pExtra_data +
sizeof(mz_uint32);
4886 if(field_data_size <
sizeof(mz_uint64) * 2)
4889 goto handle_failure;
4892 local_header_uncomp_size = MZ_READ_LE64(pSrc_field_data);
4893 local_header_comp_size = MZ_READ_LE64(pSrc_field_data +
sizeof(mz_uint64));
4895 found_zip64_ext_data_in_ldir = MZ_TRUE;
4899 pExtra_data += field_total_size;
4900 extra_size_remaining -= field_total_size;
4901 }
while(extra_size_remaining);
4906 if((has_data_descriptor) && (!local_header_comp_size) && (!local_header_crc32))
4908 mz_uint8 descriptor_buf[32];
4910 mz_uint32 num_descriptor_uint32s = ((pState->m_zip64) || (found_zip64_ext_data_in_ldir)) ? 6 : 4;
4912 if(pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs +
MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_len + local_header_extra_len + file_stat.m_comp_size, descriptor_buf,
sizeof(mz_uint32) * num_descriptor_uint32s) != (
sizeof(mz_uint32) * num_descriptor_uint32s))
4915 goto handle_failure;
4919 const mz_uint8 *pSrc =
has_id ? (descriptor_buf +
sizeof(mz_uint32)) : descriptor_buf;
4921 mz_uint32 file_crc32 = MZ_READ_LE32(pSrc);
4922 mz_uint64 comp_size = 0, uncomp_size = 0;
4924 if((pState->m_zip64) || (found_zip64_ext_data_in_ldir))
4926 comp_size = MZ_READ_LE64(pSrc +
sizeof(mz_uint32));
4927 uncomp_size = MZ_READ_LE64(pSrc +
sizeof(mz_uint32) +
sizeof(mz_uint64));
4931 comp_size = MZ_READ_LE32(pSrc +
sizeof(mz_uint32));
4932 uncomp_size = MZ_READ_LE32(pSrc +
sizeof(mz_uint32) +
sizeof(mz_uint32));
4935 if((file_crc32 != file_stat.m_crc32) || (comp_size != file_stat.m_comp_size) || (uncomp_size != file_stat.m_uncomp_size))
4938 goto handle_failure;
4943 if((local_header_crc32 != file_stat.m_crc32) || (local_header_comp_size != file_stat.m_comp_size) || (local_header_uncomp_size != file_stat.m_uncomp_size))
4946 goto handle_failure;
4952 if((flags & MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY) == 0)
4958 if(uncomp_crc32 != file_stat.m_crc32)
4974 mz_zip_internal_state *pState;
4977 if((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (!pZip->m_pRead))
4980 pState = pZip->m_pState;
4983 if(!pState->m_zip64)
4985 if(pZip->m_total_files > MZ_UINT16_MAX)
4988 if(pZip->m_archive_size > MZ_UINT32_MAX)
4993 if(pZip->m_total_files >= MZ_UINT32_MAX)
4996 if(pState->m_central_dir.m_size >= MZ_UINT32_MAX)
5000 for(i = 0; i < pZip->m_total_files; i++)
5002 if(MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG & flags)
5004 mz_uint32 found_index;
5005 mz_zip_archive_file_stat stat;
5014 if(found_index != i)
5027 mz_bool success = MZ_TRUE;
5029 mz_zip_error actual_err = MZ_ZIP_NO_ERROR;
5031 if((!pMem) || (!size))
5034 *pErr = MZ_ZIP_INVALID_PARAMETER;
5043 *pErr = zip.m_last_error;
5049 actual_err = zip.m_last_error;
5056 actual_err = zip.m_last_error;
5066#ifndef MINIZ_NO_STDIO
5069 mz_bool success = MZ_TRUE;
5071 mz_zip_error actual_err = MZ_ZIP_NO_ERROR;
5076 *pErr = MZ_ZIP_INVALID_PARAMETER;
5085 *pErr = zip.m_last_error;
5091 actual_err = zip.m_last_error;
5098 actual_err = zip.m_last_error;
5111#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
5116 p[1] = (mz_uint8)(v >> 8);
5121 p[1] = (mz_uint8)(v >> 8);
5122 p[2] = (mz_uint8)(v >> 16);
5123 p[3] = (mz_uint8)(v >> 24);
5131#define MZ_WRITE_LE16(p, v) mz_write_le16((mz_uint8 *)(p), (mz_uint16)(v))
5132#define MZ_WRITE_LE32(p, v) mz_write_le32((mz_uint8 *)(p), (mz_uint32)(v))
5133#define MZ_WRITE_LE64(p, v) mz_write_le64((mz_uint8 *)(p), (mz_uint64)(v))
5137 mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
5138 mz_zip_internal_state *pState = pZip->m_pState;
5139 mz_uint64 new_size = MZ_MAX(file_ofs + n, pState->m_mem_size);
5145 if((
sizeof(
size_t) ==
sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF))
5151 if(new_size > pState->m_mem_capacity)
5154 size_t new_capacity = MZ_MAX(64, pState->m_mem_capacity);
5156 while(new_capacity < new_size)
5159 if(NULL == (pNew_block = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pState->m_pMem, 1, new_capacity)))
5165 pState->m_pMem = pNew_block;
5166 pState->m_mem_capacity = new_capacity;
5168 memcpy((mz_uint8 *)pState->m_pMem + file_ofs, pBuf, n);
5169 pState->m_mem_size = (size_t)new_size;
5175 mz_zip_internal_state *pState;
5176 mz_bool status = MZ_TRUE;
5178 if((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || ((pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) && (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED)))
5185 pState = pZip->m_pState;
5186 pZip->m_pState = NULL;
5191#ifndef MINIZ_NO_STDIO
5194 if(pZip->m_zip_type == MZ_ZIP_TYPE_FILE)
5204 pState->m_pFile = NULL;
5210 pZip->m_pFree(pZip->m_pAlloc_opaque, pState->m_pMem);
5211 pState->m_pMem = NULL;
5214 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
5215 pZip->m_zip_mode = MZ_ZIP_MODE_INVALID;
5221 mz_bool zip64 = (flags & MZ_ZIP_FLAG_WRITE_ZIP64) != 0;
5223 if((!pZip) || (pZip->m_pState) || (!pZip->m_pWrite) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID))
5226 if(flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING)
5232 if(pZip->m_file_offset_alignment)
5235 if(pZip->m_file_offset_alignment & (pZip->m_file_offset_alignment - 1))
5243 if(!pZip->m_pRealloc)
5246 pZip->m_archive_size = existing_size;
5247 pZip->m_central_directory_file_ofs = 0;
5248 pZip->m_total_files = 0;
5250 if(NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1,
sizeof(mz_zip_internal_state))))
5253 memset(pZip->m_pState, 0,
sizeof(mz_zip_internal_state));
5259 pZip->m_pState->m_zip64 = zip64;
5260 pZip->m_pState->m_zip64_has_extended_info_fields = zip64;
5262 pZip->m_zip_type = MZ_ZIP_TYPE_USER;
5263 pZip->m_zip_mode = MZ_ZIP_MODE_WRITING;
5277 if(flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING)
5280 pZip->m_pIO_opaque = pZip;
5285 pZip->m_zip_type = MZ_ZIP_TYPE_HEAP;
5287 if(0 != (initial_allocation_size = MZ_MAX(initial_allocation_size, size_to_reserve_at_beginning)))
5289 if(NULL == (pZip->m_pState->m_pMem = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, initial_allocation_size)))
5294 pZip->m_pState->m_mem_capacity = initial_allocation_size;
5305#ifndef MINIZ_NO_STDIO
5308 mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
5309 mz_int64 cur_ofs =
MZ_FTELL64(pZip->m_pState->m_pFile);
5311 file_ofs += pZip->m_pState->m_file_archive_start_ofs;
5313 if(((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (
MZ_FSEEK64(pZip->m_pState->m_pFile, (mz_int64)file_ofs, SEEK_SET))))
5319 return MZ_FWRITE(pBuf, 1, n, pZip->m_pState->m_pFile);
5333 if(flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING)
5336 pZip->m_pIO_opaque = pZip;
5341 if(NULL == (pFile =
MZ_FOPEN(pFilename, (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING) ?
"w+b" :
"wb")))
5347 pZip->m_pState->m_pFile = pFile;
5348 pZip->m_zip_type = MZ_ZIP_TYPE_FILE;
5350 if(size_to_reserve_at_beginning)
5352 mz_uint64 cur_ofs = 0;
5359 size_t n = (size_t)MZ_MIN(
sizeof(buf), size_to_reserve_at_beginning);
5360 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_ofs, buf, n) != n)
5366 size_to_reserve_at_beginning -= n;
5367 }
while(size_to_reserve_at_beginning);
5377 if(flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING)
5380 pZip->m_pIO_opaque = pZip;
5385 pZip->m_pState->m_pFile = pFile;
5386 pZip->m_pState->m_file_archive_start_ofs =
MZ_FTELL64(pZip->m_pState->m_pFile);
5387 pZip->m_zip_type = MZ_ZIP_TYPE_CFILE;
5395 mz_zip_internal_state *pState;
5397 if((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
5400 if(flags & MZ_ZIP_FLAG_WRITE_ZIP64)
5403 if(!pZip->m_pState->m_zip64)
5408 if(pZip->m_pState->m_zip64)
5410 if(pZip->m_total_files == MZ_UINT32_MAX)
5415 if(pZip->m_total_files == MZ_UINT16_MAX)
5422 pState = pZip->m_pState;
5426#ifdef MINIZ_NO_STDIO
5430 if(pZip->m_pIO_opaque != pZip)
5433 if(pZip->m_zip_type == MZ_ZIP_TYPE_FILE)
5439 if(NULL == (pState->m_pFile =
MZ_FREOPEN(pFilename,
"r+b", pState->m_pFile)))
5450 else if(pState->m_pMem)
5453 if(pZip->m_pIO_opaque != pZip)
5456 pState->m_mem_capacity = pState->m_mem_size;
5460 else if(!pZip->m_pWrite)
5465 pZip->m_archive_size = pZip->m_central_directory_file_ofs;
5466 pZip->m_central_directory_file_ofs = 0;
5473 pZip->m_zip_mode = MZ_ZIP_MODE_WRITING;
5484mz_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)
5507#define MZ_ZIP64_MAX_LOCAL_EXTRA_FIELD_SIZE (sizeof(mz_uint16) * 2 + sizeof(mz_uint64) * 2)
5508#define MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE (sizeof(mz_uint16) * 2 + sizeof(mz_uint64) * 3)
5511 mz_uint8 *pDst = pBuf;
5515 pDst +=
sizeof(mz_uint16) * 2;
5517 mz_uint32 field_size = 0;
5522 pDst +=
sizeof(mz_uint64);
5523 field_size +=
sizeof(mz_uint64);
5529 pDst +=
sizeof(mz_uint64);
5530 field_size +=
sizeof(mz_uint64);
5533 if(pLocal_header_ofs)
5536 pDst +=
sizeof(mz_uint64);
5537 field_size +=
sizeof(mz_uint64);
5542 return (mz_uint32)(pDst - pBuf);
5545static mz_bool
mz_zip_writer_create_local_dir_header(mz_zip_archive *pZip, mz_uint8 *pDst, mz_uint16 filename_size, mz_uint16 extra_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date)
5564 mz_uint16 filename_size, mz_uint16 extra_size, mz_uint16 comment_size,
5565 mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32,
5566 mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date,
5567 mz_uint64 local_header_ofs, mz_uint32 ext_attributes)
5589 const void *pExtra, mz_uint16 extra_size,
const void *pComment, mz_uint16 comment_size,
5590 mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32,
5591 mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date,
5592 mz_uint64 local_header_ofs, mz_uint32 ext_attributes,
5593 const char *user_extra_data, mz_uint user_extra_data_len)
5595 mz_zip_internal_state *pState = pZip->m_pState;
5596 mz_uint32 central_dir_ofs = (mz_uint32)pState->m_central_dir.m_size;
5597 size_t orig_central_dir_size = pState->m_central_dir.m_size;
5600 if(!pZip->m_pState->m_zip64)
5602 if(local_header_ofs > 0xFFFFFFFF)
5607 if(((mz_uint64)pState->m_central_dir.m_size +
MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size + extra_size + user_extra_data_len + comment_size) >= MZ_UINT32_MAX)
5610 if(!
mz_zip_writer_create_central_dir_header(pZip, central_dir_header, filename_size, extra_size + user_extra_data_len, comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_header_ofs, ext_attributes))
5631 if(*pArchive_name ==
'/')
5634 while(*pArchive_name)
5636 if((*pArchive_name ==
'\\') || (*pArchive_name ==
':'))
5648 if(!pZip->m_file_offset_alignment)
5650 n = (mz_uint32)(pZip->m_archive_size & (pZip->m_file_offset_alignment - 1));
5651 return (mz_uint)((pZip->m_file_offset_alignment - n) & (pZip->m_file_offset_alignment - 1));
5657 memset(buf, 0, MZ_MIN(
sizeof(buf), n));
5660 mz_uint32 s = MZ_MIN(
sizeof(buf), n);
5661 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_file_ofs, buf, s) != s)
5670mz_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,
5671 mz_uint64 uncomp_size, mz_uint32 uncomp_crc32)
5673 return mz_zip_writer_add_mem_ex_v2(pZip, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, uncomp_size, uncomp_crc32, NULL, NULL, 0, NULL, 0);
5676mz_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,
5677 mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified,
5678 const char *user_extra_data, mz_uint user_extra_data_len,
const char *user_extra_data_central, mz_uint user_extra_data_central_len)
5680 mz_uint16 method = 0, dos_time = 0, dos_date = 0;
5681 mz_uint level, ext_attributes = 0, num_alignment_padding_bytes;
5682 mz_uint64 local_dir_header_ofs = pZip->m_archive_size, cur_archive_file_ofs = pZip->m_archive_size, comp_size = 0;
5683 size_t archive_name_size;
5685 tdefl_compressor *pComp = NULL;
5686 mz_bool store_data_uncompressed;
5687 mz_zip_internal_state *pState;
5688 mz_uint8 *pExtra_data = NULL;
5689 mz_uint32 extra_size = 0;
5691 mz_uint16 bit_flags = 0;
5693 if(uncomp_size || (buf_size && !(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)))
5696 if(level_and_flags & MZ_ZIP_FLAG_UTF8_FILENAME)
5699 if((
int)level_and_flags < 0)
5701 level = level_and_flags & 0xF;
5702 store_data_uncompressed = ((!level) || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA));
5704 if((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || ((buf_size) && (!pBuf)) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level >
MZ_UBER_COMPRESSION))
5707 pState = pZip->m_pState;
5711 if(pZip->m_total_files == MZ_UINT32_MAX)
5716 if(pZip->m_total_files == MZ_UINT16_MAX)
5718 pState->m_zip64 = MZ_TRUE;
5721 if((buf_size > 0xFFFFFFFF) || (uncomp_size > 0xFFFFFFFF))
5723 pState->m_zip64 = MZ_TRUE;
5728 if((!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (uncomp_size))
5734 if(last_modified != NULL)
5740#ifndef MINIZ_NO_TIME
5749 archive_name_size = strlen(pArchive_name);
5750 if(archive_name_size > MZ_UINT16_MAX)
5759 if(!pState->m_zip64)
5764 pState->m_zip64 = MZ_TRUE;
5769 if((archive_name_size) && (pArchive_name[archive_name_size - 1] ==
'/'))
5775 if((buf_size) || (uncomp_size))
5783 if((!store_data_uncompressed) && (buf_size))
5785 if(NULL == (pComp = (tdefl_compressor *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1,
sizeof(tdefl_compressor))))
5791 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
5795 local_dir_header_ofs += num_alignment_padding_bytes;
5796 if(pZip->m_file_offset_alignment)
5798 MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0);
5800 cur_archive_file_ofs += num_alignment_padding_bytes;
5802 MZ_CLEAR_OBJ(local_dir_header);
5804 if(!store_data_uncompressed || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
5811 if(uncomp_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX)
5813 pExtra_data = extra_data;
5815 (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
5818 if(!
mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, extra_size + user_extra_data_len, 0, 0, 0, method, bit_flags, dos_time, dos_date))
5821 if(pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header,
sizeof(local_dir_header)) !=
sizeof(local_dir_header))
5824 cur_archive_file_ofs +=
sizeof(local_dir_header);
5826 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
5828 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
5831 cur_archive_file_ofs += archive_name_size;
5833 if(pExtra_data != NULL)
5835 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, extra_data, extra_size) != extra_size)
5838 cur_archive_file_ofs += extra_size;
5843 if((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX))
5845 if(!
mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, user_extra_data_len, 0, 0, 0, method, bit_flags, dos_time, dos_date))
5848 if(pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header,
sizeof(local_dir_header)) !=
sizeof(local_dir_header))
5851 cur_archive_file_ofs +=
sizeof(local_dir_header);
5853 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
5855 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
5858 cur_archive_file_ofs += archive_name_size;
5861 if(user_extra_data_len > 0)
5863 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, user_extra_data, user_extra_data_len) != user_extra_data_len)
5866 cur_archive_file_ofs += user_extra_data_len;
5869 if(!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
5872 uncomp_size = buf_size;
5873 if(uncomp_size <= 3)
5876 store_data_uncompressed = MZ_TRUE;
5880 if(store_data_uncompressed)
5882 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pBuf, buf_size) != buf_size)
5884 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
5888 cur_archive_file_ofs += buf_size;
5889 comp_size = buf_size;
5902 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
5910 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
5922 if(pExtra_data == NULL)
5924 if((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX))
5937 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_footer, local_dir_footer_size) != local_dir_footer_size)
5940 cur_archive_file_ofs += local_dir_footer_size;
5943 if(pExtra_data != NULL)
5946 (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
5950 comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes,
5951 user_extra_data_central, user_extra_data_central_len))
5954 pZip->m_total_files++;
5955 pZip->m_archive_size = cur_archive_file_ofs;
5960#ifndef MINIZ_NO_STDIO
5961mz_bool
mz_zip_writer_add_cfile(mz_zip_archive *pZip,
const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add,
const MZ_TIME_T *pFile_time,
const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
5962 const char *user_extra_data, mz_uint user_extra_data_len,
const char *user_extra_data_central, mz_uint user_extra_data_central_len)
5965 mz_uint uncomp_crc32 =
MZ_CRC32_INIT, level, num_alignment_padding_bytes;
5966 mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0;
5967 mz_uint64 local_dir_header_ofs, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = size_to_add, comp_size = 0;
5968 size_t archive_name_size;
5970 mz_uint8 *pExtra_data = NULL;
5971 mz_uint32 extra_size = 0;
5973 mz_zip_internal_state *pState;
5975 if(level_and_flags & MZ_ZIP_FLAG_UTF8_FILENAME)
5978 if((
int)level_and_flags < 0)
5980 level = level_and_flags & 0xF;
5983 if((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level >
MZ_UBER_COMPRESSION))
5986 pState = pZip->m_pState;
5988 if((!pState->m_zip64) && (uncomp_size > MZ_UINT32_MAX))
5992 pState->m_zip64 = MZ_TRUE;
5996 if(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)
6004 if(pZip->m_total_files == MZ_UINT32_MAX)
6009 if(pZip->m_total_files == MZ_UINT16_MAX)
6011 pState->m_zip64 = MZ_TRUE;
6016 archive_name_size = strlen(pArchive_name);
6017 if(archive_name_size > MZ_UINT16_MAX)
6026 if(!pState->m_zip64)
6031 pState->m_zip64 = MZ_TRUE;
6036#ifndef MINIZ_NO_TIME
6043 if(uncomp_size <= 3)
6051 cur_archive_file_ofs += num_alignment_padding_bytes;
6052 local_dir_header_ofs = cur_archive_file_ofs;
6054 if(pZip->m_file_offset_alignment)
6056 MZ_ASSERT((cur_archive_file_ofs & (pZip->m_file_offset_alignment - 1)) == 0);
6059 if(uncomp_size && level)
6064 MZ_CLEAR_OBJ(local_dir_header);
6067 if(uncomp_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX)
6069 pExtra_data = extra_data;
6071 (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
6074 if(!
mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, extra_size + user_extra_data_len, 0, 0, 0, method, gen_flags, dos_time, dos_date))
6077 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header,
sizeof(local_dir_header)) !=
sizeof(local_dir_header))
6080 cur_archive_file_ofs +=
sizeof(local_dir_header);
6082 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
6087 cur_archive_file_ofs += archive_name_size;
6089 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, extra_data, extra_size) != extra_size)
6092 cur_archive_file_ofs += extra_size;
6096 if((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX))
6098 if(!
mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, user_extra_data_len, 0, 0, 0, method, gen_flags, dos_time, dos_date))
6101 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header,
sizeof(local_dir_header)) !=
sizeof(local_dir_header))
6104 cur_archive_file_ofs +=
sizeof(local_dir_header);
6106 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
6111 cur_archive_file_ofs += archive_name_size;
6114 if(user_extra_data_len > 0)
6116 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, user_extra_data, user_extra_data_len) != user_extra_data_len)
6119 cur_archive_file_ofs += user_extra_data_len;
6124 mz_uint64 uncomp_remaining = uncomp_size;
6125 void *pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, MZ_ZIP_MAX_IO_BUF_SIZE);
6133 while(uncomp_remaining)
6135 mz_uint n = (mz_uint)MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, uncomp_remaining);
6136 if((
MZ_FREAD(pRead_buf, 1, n, pSrc_file) != n) || (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pRead_buf, n) != n))
6138 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6141 uncomp_crc32 = (mz_uint32)
mz_crc32(uncomp_crc32, (
const mz_uint8 *)pRead_buf, n);
6142 uncomp_remaining -= n;
6143 cur_archive_file_ofs += n;
6145 comp_size = uncomp_size;
6149 mz_bool result = MZ_FALSE;
6151 tdefl_compressor *pComp = (tdefl_compressor *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1,
sizeof(tdefl_compressor));
6154 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6164 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
6165 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6171 size_t in_buf_size = (mz_uint32)MZ_MIN(uncomp_remaining, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
6172 tdefl_status status;
6174 if(
MZ_FREAD(pRead_buf, 1, in_buf_size, pSrc_file) != in_buf_size)
6180 uncomp_crc32 = (mz_uint32)
mz_crc32(uncomp_crc32, (
const mz_uint8 *)pRead_buf, in_buf_size);
6181 uncomp_remaining -= in_buf_size;
6183 status =
tdefl_compress_buffer(pComp, pRead_buf, in_buf_size, uncomp_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH);
6184 if(status == TDEFL_STATUS_DONE)
6189 else if(status != TDEFL_STATUS_OKAY)
6196 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
6200 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6208 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6216 if(pExtra_data == NULL)
6218 if(comp_size > MZ_UINT32_MAX)
6231 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_footer, local_dir_footer_size) != local_dir_footer_size)
6234 cur_archive_file_ofs += local_dir_footer_size;
6236 if(pExtra_data != NULL)
6239 (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
6243 uncomp_size, comp_size, uncomp_crc32, method, gen_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes,
6244 user_extra_data_central, user_extra_data_central_len))
6247 pZip->m_total_files++;
6248 pZip->m_archive_size = cur_archive_file_ofs;
6253mz_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)
6255 MZ_FILE *pSrc_file = NULL;
6256 mz_uint64 uncomp_size = 0;
6257 MZ_TIME_T file_modified_time;
6258 MZ_TIME_T *pFile_time = NULL;
6260 memset(&file_modified_time, 0,
sizeof(file_modified_time));
6262#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_STDIO)
6263 pFile_time = &file_modified_time;
6268 pSrc_file =
MZ_FOPEN(pSrc_filename,
"rb");
6276 mz_bool status =
mz_zip_writer_add_cfile(pZip, pArchive_name, pSrc_file, uncomp_size, pFile_time, pComment, comment_size, level_and_flags, NULL, 0, NULL, 0);
6292 if((pUncomp_size) || (pComp_size) || (pLocal_header_ofs) || (pDisk_start))
6294 mz_uint8 new_ext_block[64];
6295 mz_uint8 *pDst = new_ext_block;
6298 pDst +=
sizeof(mz_uint16) * 2;
6303 pDst +=
sizeof(mz_uint64);
6309 pDst +=
sizeof(mz_uint64);
6312 if(pLocal_header_ofs)
6315 pDst +=
sizeof(mz_uint64);
6321 pDst +=
sizeof(mz_uint32);
6324 mz_write_le16(new_ext_block +
sizeof(mz_uint16), (mz_uint16)((pDst - new_ext_block) -
sizeof(mz_uint16) * 2));
6330 if((pExt) && (ext_len))
6332 mz_uint32 extra_size_remaining = ext_len;
6333 const mz_uint8 *pExtra_data = pExt;
6337 mz_uint32 field_id, field_data_size, field_total_size;
6339 if(extra_size_remaining < (
sizeof(mz_uint16) * 2))
6342 field_id = MZ_READ_LE16(pExtra_data);
6343 field_data_size = MZ_READ_LE16(pExtra_data +
sizeof(mz_uint16));
6344 field_total_size = field_data_size +
sizeof(mz_uint16) * 2;
6346 if(field_total_size > extra_size_remaining)
6355 pExtra_data += field_total_size;
6356 extra_size_remaining -= field_total_size;
6357 }
while(extra_size_remaining);
6366 mz_uint n, bit_flags, num_alignment_padding_bytes, src_central_dir_following_data_size;
6367 mz_uint64 src_archive_bytes_remaining, local_dir_header_ofs;
6368 mz_uint64 cur_src_file_ofs, cur_dst_file_ofs;
6370 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
6372 size_t orig_central_dir_size;
6373 mz_zip_internal_state *pState;
6375 const mz_uint8 *pSrc_central_header;
6376 mz_zip_archive_file_stat src_file_stat;
6377 mz_uint32 src_filename_len, src_comment_len, src_ext_len;
6378 mz_uint32 local_header_filename_size, local_header_extra_len;
6379 mz_uint64 local_header_comp_size, local_header_uncomp_size;
6380 mz_bool found_zip64_ext_data_in_ldir = MZ_FALSE;
6383 if((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pSource_zip->m_pRead))
6386 pState = pZip->m_pState;
6389 if((pSource_zip->m_pState->m_zip64) && (!pZip->m_pState->m_zip64))
6393 if(NULL == (pSrc_central_header =
mz_zip_get_cdh(pSource_zip, src_file_index)))
6402 src_central_dir_following_data_size = src_filename_len + src_ext_len + src_comment_len;
6410 if(!pState->m_zip64)
6412 if(pZip->m_total_files == MZ_UINT16_MAX)
6418 if(pZip->m_total_files == MZ_UINT32_MAX)
6425 cur_src_file_ofs = src_file_stat.m_local_header_ofs;
6426 cur_dst_file_ofs = pZip->m_archive_size;
6442 src_archive_bytes_remaining = local_header_filename_size + local_header_extra_len + src_file_stat.m_comp_size;
6445 if((local_header_extra_len) && ((local_header_comp_size == MZ_UINT32_MAX) || (local_header_uncomp_size == MZ_UINT32_MAX)))
6454 if(pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, src_file_stat.m_local_header_ofs +
MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_size, file_data_array.
m_p, local_header_extra_len) != local_header_extra_len)
6460 mz_uint32 extra_size_remaining = local_header_extra_len;
6461 const mz_uint8 *pExtra_data = (
const mz_uint8 *)file_data_array.
m_p;
6465 mz_uint32 field_id, field_data_size, field_total_size;
6467 if(extra_size_remaining < (
sizeof(mz_uint16) * 2))
6473 field_id = MZ_READ_LE16(pExtra_data);
6474 field_data_size = MZ_READ_LE16(pExtra_data +
sizeof(mz_uint16));
6475 field_total_size = field_data_size +
sizeof(mz_uint16) * 2;
6477 if(field_total_size > extra_size_remaining)
6485 const mz_uint8 *pSrc_field_data = pExtra_data +
sizeof(mz_uint32);
6487 if(field_data_size <
sizeof(mz_uint64) * 2)
6493 local_header_uncomp_size = MZ_READ_LE64(pSrc_field_data);
6494 local_header_comp_size = MZ_READ_LE64(pSrc_field_data +
sizeof(mz_uint64));
6496 found_zip64_ext_data_in_ldir = MZ_TRUE;
6500 pExtra_data += field_total_size;
6501 extra_size_remaining -= field_total_size;
6502 }
while(extra_size_remaining);
6507 if(!pState->m_zip64)
6511 mz_uint64 approx_new_archive_size = cur_dst_file_ofs + num_alignment_padding_bytes +
MZ_ZIP_LOCAL_DIR_HEADER_SIZE + src_archive_bytes_remaining + (
sizeof(mz_uint32) * 4) +
6514 if(approx_new_archive_size >= MZ_UINT32_MAX)
6522 cur_dst_file_ofs += num_alignment_padding_bytes;
6524 local_dir_header_ofs = cur_dst_file_ofs;
6525 if(pZip->m_file_offset_alignment)
6527 MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0);
6537 if(NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (
size_t)MZ_MAX(32U, MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, src_archive_bytes_remaining)))))
6540 while(src_archive_bytes_remaining)
6542 n = (mz_uint)MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, src_archive_bytes_remaining);
6543 if(pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, n) != n)
6545 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
6548 cur_src_file_ofs += n;
6550 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n)
6552 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
6555 cur_dst_file_ofs += n;
6557 src_archive_bytes_remaining -= n;
6565 if((pSource_zip->m_pState->m_zip64) || (found_zip64_ext_data_in_ldir))
6574 if(pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, (
sizeof(mz_uint32) * 6)) != (
sizeof(mz_uint32) * 6))
6576 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
6587 if(pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf,
sizeof(mz_uint32) * 4) !=
sizeof(mz_uint32) * 4)
6589 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
6595 if(pZip->m_pState->m_zip64)
6598 const mz_uint32 *pSrc_descriptor = (
const mz_uint32 *)((
const mz_uint8 *)pBuf + (
has_id ?
sizeof(mz_uint32) : 0));
6599 const mz_uint32 src_crc32 = pSrc_descriptor[0];
6600 const mz_uint64 src_comp_size = pSrc_descriptor[1];
6601 const mz_uint64 src_uncomp_size = pSrc_descriptor[2];
6604 mz_write_le32((mz_uint8 *)pBuf +
sizeof(mz_uint32) * 1, src_crc32);
6605 mz_write_le64((mz_uint8 *)pBuf +
sizeof(mz_uint32) * 2, src_comp_size);
6606 mz_write_le64((mz_uint8 *)pBuf +
sizeof(mz_uint32) * 4, src_uncomp_size);
6608 n =
sizeof(mz_uint32) * 6;
6613 n =
sizeof(mz_uint32) * (
has_id ? 4 : 3);
6617 if(pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n)
6619 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
6623 cur_src_file_ofs += n;
6624 cur_dst_file_ofs += n;
6626 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
6629 orig_central_dir_size = pState->m_central_dir.m_size;
6685 if(cur_dst_file_ofs > MZ_UINT32_MAX)
6688 if(local_dir_header_ofs >= MZ_UINT32_MAX)
6704 if(pState->m_central_dir.m_size >= MZ_UINT32_MAX)
6711 n = (mz_uint32)orig_central_dir_size;
6718 pZip->m_total_files++;
6719 pZip->m_archive_size = cur_dst_file_ofs;
6726 mz_zip_internal_state *pState;
6727 mz_uint64 central_dir_ofs, central_dir_size;
6730 if((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING))
6733 pState = pZip->m_pState;
6737 if((pZip->m_total_files > MZ_UINT32_MAX) || (pState->m_central_dir.m_size >= MZ_UINT32_MAX))
6746 central_dir_ofs = 0;
6747 central_dir_size = 0;
6748 if(pZip->m_total_files)
6751 central_dir_ofs = pZip->m_archive_size;
6752 central_dir_size = pState->m_central_dir.m_size;
6753 pZip->m_central_directory_file_ofs = central_dir_ofs;
6754 if(pZip->m_pWrite(pZip->m_pIO_opaque, central_dir_ofs, pState->m_central_dir.m_p, (
size_t)central_dir_size) != central_dir_size)
6757 pZip->m_archive_size += central_dir_size;
6763 mz_uint64 rel_ofs_to_zip64_ecdr = pZip->m_archive_size;
6801#ifndef MINIZ_NO_STDIO
6802 if((pState->m_pFile) && (
MZ_FFLUSH(pState->m_pFile) == EOF))
6808 pZip->m_zip_mode = MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED;
6814 if((!ppBuf) || (!pSize))
6820 if((!pZip) || (!pZip->m_pState))
6829 *ppBuf = pZip->m_pState->m_pMem;
6830 *pSize = pZip->m_pState->m_mem_size;
6831 pZip->m_pState->m_pMem = NULL;
6832 pZip->m_pState->m_mem_size = pZip->m_pState->m_mem_capacity = 0;
6842#ifndef MINIZ_NO_STDIO
6848mz_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)
6850 mz_bool status, created_new_archive = MZ_FALSE;
6851 mz_zip_archive zip_archive;
6853 mz_zip_error actual_err = MZ_ZIP_NO_ERROR;
6856 if((
int)level_and_flags < 0)
6859 if((!pZip_filename) || (!pArchive_name) || ((buf_size) && (!pBuf)) || ((comment_size) && (!pComment)) || ((level_and_flags & 0xF) >
MZ_UBER_COMPRESSION))
6862 *pErr = MZ_ZIP_INVALID_PARAMETER;
6869 *pErr = MZ_ZIP_INVALID_FILENAME;
6881 *pErr = zip_archive.m_last_error;
6885 created_new_archive = MZ_TRUE;
6890 if(!
mz_zip_reader_init_file_v2(&zip_archive, pZip_filename, level_and_flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY, 0, 0))
6893 *pErr = zip_archive.m_last_error;
6900 *pErr = zip_archive.m_last_error;
6908 status =
mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0);
6909 actual_err = zip_archive.m_last_error;
6915 actual_err = zip_archive.m_last_error;
6923 actual_err = zip_archive.m_last_error;
6928 if((!status) && (created_new_archive))
6932 (void)ignoredStatus;
6943 mz_uint32 file_index;
6944 mz_zip_archive zip_archive;
6950 if((!pZip_filename) || (!pArchive_name))
6953 *pErr = MZ_ZIP_INVALID_PARAMETER;
6962 *pErr = zip_archive.m_last_error;
6975 *pErr = zip_archive.m_last_error;
6993 return pZip ? pZip->m_zip_mode : MZ_ZIP_MODE_INVALID;
6998 return pZip ? pZip->m_zip_type : MZ_ZIP_TYPE_INVALID;
7003 mz_zip_error prev_err;
7006 return MZ_ZIP_INVALID_PARAMETER;
7008 prev_err = pZip->m_last_error;
7010 pZip->m_last_error = err_num;
7017 return MZ_ZIP_INVALID_PARAMETER;
7019 return pZip->m_last_error;
7029 mz_zip_error prev_err;
7032 return MZ_ZIP_INVALID_PARAMETER;
7034 prev_err = pZip->m_last_error;
7036 pZip->m_last_error = MZ_ZIP_NO_ERROR;
7044 case MZ_ZIP_NO_ERROR:
7046 case MZ_ZIP_UNDEFINED_ERROR:
7047 return "undefined error";
7048 case MZ_ZIP_TOO_MANY_FILES:
7049 return "too many files";
7050 case MZ_ZIP_FILE_TOO_LARGE:
7051 return "file too large";
7052 case MZ_ZIP_UNSUPPORTED_METHOD:
7053 return "unsupported method";
7054 case MZ_ZIP_UNSUPPORTED_ENCRYPTION:
7055 return "unsupported encryption";
7056 case MZ_ZIP_UNSUPPORTED_FEATURE:
7057 return "unsupported feature";
7058 case MZ_ZIP_FAILED_FINDING_CENTRAL_DIR:
7059 return "failed finding central directory";
7060 case MZ_ZIP_NOT_AN_ARCHIVE:
7061 return "not a ZIP archive";
7062 case MZ_ZIP_INVALID_HEADER_OR_CORRUPTED:
7063 return "invalid header or archive is corrupted";
7064 case MZ_ZIP_UNSUPPORTED_MULTIDISK:
7065 return "unsupported multidisk archive";
7066 case MZ_ZIP_DECOMPRESSION_FAILED:
7067 return "decompression failed or archive is corrupted";
7068 case MZ_ZIP_COMPRESSION_FAILED:
7069 return "compression failed";
7070 case MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE:
7071 return "unexpected decompressed size";
7072 case MZ_ZIP_CRC_CHECK_FAILED:
7073 return "CRC-32 check failed";
7074 case MZ_ZIP_UNSUPPORTED_CDIR_SIZE:
7075 return "unsupported central directory size";
7076 case MZ_ZIP_ALLOC_FAILED:
7077 return "allocation failed";
7078 case MZ_ZIP_FILE_OPEN_FAILED:
7079 return "file open failed";
7080 case MZ_ZIP_FILE_CREATE_FAILED:
7081 return "file create failed";
7082 case MZ_ZIP_FILE_WRITE_FAILED:
7083 return "file write failed";
7084 case MZ_ZIP_FILE_READ_FAILED:
7085 return "file read failed";
7086 case MZ_ZIP_FILE_CLOSE_FAILED:
7087 return "file close failed";
7088 case MZ_ZIP_FILE_SEEK_FAILED:
7089 return "file seek failed";
7090 case MZ_ZIP_FILE_STAT_FAILED:
7091 return "file stat failed";
7092 case MZ_ZIP_INVALID_PARAMETER:
7093 return "invalid parameter";
7094 case MZ_ZIP_INVALID_FILENAME:
7095 return "invalid filename";
7096 case MZ_ZIP_BUF_TOO_SMALL:
7097 return "buffer too small";
7098 case MZ_ZIP_INTERNAL_ERROR:
7099 return "internal error";
7100 case MZ_ZIP_FILE_NOT_FOUND:
7101 return "file not found";
7102 case MZ_ZIP_ARCHIVE_TOO_LARGE:
7103 return "archive is too large";
7104 case MZ_ZIP_VALIDATION_FAILED:
7105 return "validation failed";
7106 case MZ_ZIP_WRITE_CALLBACK_FAILED:
7107 return "write calledback failed";
7108 case MZ_ZIP_TOTAL_ERRORS:
7113 return "unknown error";
7119 if((!pZip) || (!pZip->m_pState))
7122 return pZip->m_pState->m_zip64;
7127 if((!pZip) || (!pZip->m_pState))
7130 return pZip->m_pState->m_central_dir.m_size;
7135 return pZip ? pZip->m_total_files : 0;
7142 return pZip->m_archive_size;
7147 if((!pZip) || (!pZip->m_pState))
7149 return pZip->m_pState->m_file_archive_start_ofs;
7154 if((!pZip) || (!pZip->m_pState))
7156 return pZip->m_pState->m_pFile;
7161 if((!pZip) || (!pZip->m_pState) || (!pBuf) || (!pZip->m_pRead))
7164 return pZip->m_pRead(pZip->m_pIO_opaque, file_ofs, pBuf, n);
7173 if(filename_buf_size)
7174 pFilename[0] =
'\0';
7179 if(filename_buf_size)
7181 n = MZ_MIN(n, filename_buf_size - 1);
7183 pFilename[n] =
'\0';
7198 if(pZip->m_zip_mode == MZ_ZIP_MODE_READING)
7200 else if((pZip->m_zip_mode == MZ_ZIP_MODE_WRITING) || (pZip->m_zip_mode == MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED))
static bool has_id(const jsont &json)
Return true iff the argument has a "@id" key.
#define MZ_WRITE_LE32(p, v)
mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
static mz_bool mz_zip_writer_add_to_central_dir(mz_zip_archive *pZip, const char *pFilename, mz_uint16 filename_size, const void *pExtra, mz_uint16 extra_size, const void *pComment, mz_uint16 comment_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date, mz_uint64 local_header_ofs, mz_uint32 ext_attributes, const char *user_extra_data, mz_uint user_extra_data_len)
mz_bool mz_zip_is_zip64(mz_zip_archive *pZip)
static MZ_FORCEINLINE mz_bool mz_zip_array_ensure_room(mz_zip_archive *pZip, mz_zip_array *pArray, size_t n)
static const mz_uint8 s_tdefl_len_extra[256]
mz_bool mz_zip_reader_end(mz_zip_archive *pZip)
mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags)
mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip)
mz_zip_type mz_zip_get_type(mz_zip_archive *pZip)
static size_t mz_zip_file_read_func(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n)
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)
void * miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size)
static const mz_uint16 s_tdefl_len_sym[256]
mz_bool mz_zip_end(mz_zip_archive *pZip)
static int tdefl_flush_block(tdefl_compressor *d, int flush)
static MZ_FORCEINLINE void mz_write_le32(mz_uint8 *p, mz_uint32 v)
mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip)
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)
mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning)
#define MZ_WRITE_LE16(p, v)
void * tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
static void mz_zip_reader_sort_central_dir_offsets_by_filename(mz_zip_archive *pZip)
static void tdefl_start_dynamic_block(tdefl_compressor *d)
mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags)
int mz_deflateReset(mz_streamp pStream)
#define TINFL_GET_BYTE(state_index, c)
#define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size)
static mz_bool mz_zip_writer_end_internal(mz_zip_archive *pZip, mz_bool set_last_error)
size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip)
static mz_bool mz_zip_file_stat_internal(mz_zip_archive *pZip, mz_uint file_index, const mz_uint8 *pCentral_dir_header, mz_zip_archive_file_stat *pStat, mz_bool *pFound_zip64_extra_data)
int mz_inflateInit(mz_streamp pStream)
int mz_inflate(mz_streamp pStream, int flush)
int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
mz_uint32 tdefl_get_adler32(tdefl_compressor *d)
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)
#define TDEFL_RLE_ZERO_CODE_SIZE()
mz_ulong mz_compressBound(mz_ulong source_len)
static mz_bool mz_zip_set_file_times(const char *pFilename, MZ_TIME_T access_time, MZ_TIME_T modified_time)
static MZ_FORCEINLINE void mz_write_le16(mz_uint8 *p, mz_uint16 v)
static mz_bool mz_zip_reader_locate_header_sig(mz_zip_archive *pZip, mz_uint32 record_sig, mz_uint32 record_size, mz_int64 *pOfs)
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)
int mz_deflateEnd(mz_streamp pStream)
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)
mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip)
#define MZ_FREOPEN(f, m, s)
static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n)
static const mz_uint8 s_tdefl_small_dist_sym[512]
tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags)
static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d)
size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n)
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)
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)
@ MZ_ZIP64_ECDH_VERSION_MADE_BY_OFS
@ MZ_ZIP_CDH_FILENAME_LEN_OFS
@ MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR
@ MZ_ZIP_LOCAL_DIR_HEADER_SIG
@ MZ_ZIP_CDH_FILE_DATE_OFS
@ MZ_ZIP_LDH_BIT_FLAG_OFS
@ MZ_ZIP_ECDH_NUM_DISK_CDIR_OFS
@ MZ_ZIP_CDH_VERSION_NEEDED_OFS
@ MZ_ZIP_DATA_DESCRIPTER_SIZE64
@ MZ_ZIP_CDH_LOCAL_HEADER_OFS
@ MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG
@ MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8
@ MZ_ZIP64_ECDH_NUM_DISK_CDIR_OFS
@ MZ_ZIP_CDH_COMPRESSED_SIZE_OFS
@ MZ_ZIP_DATA_DESCRIPTER_SIZE32
@ MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS
@ MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_COMPRESSED_PATCH_FLAG
@ MZ_ZIP64_ECDL_NUM_DISK_CDIR_OFS
@ MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS
@ MZ_ZIP_ECDH_CDIR_SIZE_OFS
@ MZ_ZIP_LDH_FILENAME_LEN_OFS
@ MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE
@ MZ_ZIP_DOS_DIR_ATTRIBUTE_BITFLAG
@ MZ_ZIP_LDH_FILE_TIME_OFS
@ MZ_ZIP64_ECDH_VERSION_NEEDED_OFS
@ MZ_ZIP_CDH_EXTRA_LEN_OFS
@ MZ_ZIP_LDH_FILE_DATE_OFS
@ MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS
@ MZ_ZIP64_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS
@ MZ_ZIP_LDH_COMPRESSED_SIZE_OFS
@ MZ_ZIP_CDH_FILE_TIME_OFS
@ MZ_ZIP_VERSION_MADE_BY_DOS_FILESYSTEM_ID
@ MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS
@ MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID
@ MZ_ZIP_CENTRAL_DIR_HEADER_SIG
@ MZ_ZIP_ECDH_COMMENT_SIZE_OFS
@ MZ_ZIP64_ECDH_CDIR_SIZE_OFS
@ MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS
@ MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_USES_STRONG_ENCRYPTION
@ MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG
@ MZ_ZIP_CDH_DISK_START_OFS
@ MZ_ZIP64_ECDH_CDIR_TOTAL_ENTRIES_OFS
@ MZ_ZIP_CDH_INTERNAL_ATTR_OFS
@ MZ_ZIP_LDH_VERSION_NEEDED_OFS
@ MZ_ZIP_ECDH_CDIR_OFS_OFS
@ MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG
@ MZ_ZIP_LDH_EXTRA_LEN_OFS
@ MZ_ZIP_CDH_EXTERNAL_ATTR_OFS
@ MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_LOCAL_DIR_IS_MASKED
@ MZ_ZIP64_ECDH_NUM_THIS_DISK_OFS
@ MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE
@ MZ_ZIP_LOCAL_DIR_HEADER_SIZE
@ MZ_ZIP64_ECDH_CDIR_OFS_OFS
@ MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS
@ MZ_ZIP_CDH_BIT_FLAG_OFS
@ MZ_ZIP_CDH_COMMENT_LEN_OFS
@ MZ_ZIP_CENTRAL_DIR_HEADER_SIZE
@ MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE
@ MZ_ZIP_DATA_DESCRIPTOR_ID
@ MZ_ZIP_CDH_VERSION_MADE_BY_OFS
@ MZ_ZIP_ECDH_NUM_THIS_DISK_OFS
@ MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_IS_ENCRYPTED
@ MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS
static size_t mz_zip_file_write_func(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n)
mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index)
void * tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
static mz_bool tdefl_output_buffer_putter(const void *pBuf, int len, void *pUser)
static mz_bool mz_zip_get_file_modified_time(const char *pFilename, MZ_TIME_T *pTime)
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)
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)
unsigned char mz_validate_uint32[sizeof(mz_uint32)==4 ? 1 :-1]
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)
void * miniz_def_alloc_func(void *opaque, size_t items, size_t size)
#define TINFL_MEMCPY(d, s, l)
#define TINFL_GET_BITS(state_index, b, n)
mz_bool mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *pIndex)
static const mz_uint8 s_tdefl_small_dist_extra[512]
tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d)
mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size)
static mz_bool mz_zip_reader_init_internal(mz_zip_archive *pZip, mz_uint flags)
static mz_bool mz_zip_reader_end_internal(mz_zip_archive *pZip, mz_bool set_last_error)
mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip)
mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint flags)
#define TINFL_HUFF_DECODE(state_index, sym, pHuff)
mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip)
mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags)
tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush)
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)
mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr)
static const mz_uint8 s_tdefl_large_dist_extra[128]
static const mz_uint s_tdefl_num_probes[11]
int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy)
mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags)
const char * mz_version(void)
static mz_bool tdefl_compress_normal(tdefl_compressor *d)
int mz_deflateInit(mz_streamp pStream, int level)
static size_t mz_zip_file_write_callback(void *pOpaque, mz_uint64 ofs, const void *pBuf, size_t n)
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)
static MZ_FORCEINLINE void mz_zip_array_init(mz_zip_array *pArray, mz_uint32 element_size)
const char * mz_zip_get_error_string(mz_zip_error mz_err)
static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len)
void * mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags)
static MZ_FORCEINLINE const mz_uint8 * mz_zip_get_cdh(mz_zip_archive *pZip, mz_uint file_index)
void miniz_def_free_func(void *opaque, void *address)
static void tdefl_huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size)
static void tdefl_start_static_block(tdefl_compressor *d)
int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level)
static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint flags)
mz_bool mz_zip_writer_end(mz_zip_archive *pZip)
static mz_bool mz_zip_writer_create_central_dir_header(mz_zip_archive *pZip, mz_uint8 *pDst, mz_uint16 filename_size, mz_uint16 extra_size, mz_uint16 comment_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date, mz_uint64 local_header_ofs, mz_uint32 ext_attributes)
mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags)
#define TINFL_MEMSET(p, c, l)
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)
static size_t mz_zip_heap_write_func(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n)
static void mz_zip_time_t_to_dos_time(MZ_TIME_T time, mz_uint16 *pDOS_time, mz_uint16 *pDOS_date)
int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags)
static MZ_FORCEINLINE mz_bool mz_zip_array_push_back(mz_zip_archive *pZip, mz_zip_array *pArray, const void *pElements, size_t n)
static MZ_TIME_T mz_zip_dos_to_time_t(int dos_time, int dos_date)
mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index)
mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size)
const char * mz_error(int err)
mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len)
void mz_zip_zero_struct(mz_zip_archive *pZip)
static MZ_FORCEINLINE void mz_zip_array_clear(mz_zip_archive *pZip, mz_zip_array *pArray)
static MZ_FORCEINLINE int mz_zip_filename_compare(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, const char *pR, mz_uint r_len)
static mz_uint32 mz_zip_writer_create_zip64_extra_data(mz_uint8 *pBuf, mz_uint64 *pUncomp_size, mz_uint64 *pComp_size, mz_uint64 *pLocal_header_ofs)
mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip)
tdefl_compressor * tdefl_compressor_alloc()
MZ_FILE * mz_zip_get_cfile(mz_zip_archive *pZip)
static mz_uint mz_zip_writer_compute_padding_needed_for_file_alignment(mz_zip_archive *pZip)
int mz_inflateInit2(mz_streamp pStream, int window_bits)
static mz_bool mz_zip_writer_add_put_buf_callback(const void *pBuf, int len, void *pUser)
static mz_bool mz_zip_writer_validate_archive_name(const char *pArchive_name)
static size_t mz_zip_mem_read_func(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n)
static MZ_FORCEINLINE mz_bool mz_zip_reader_filename_less(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, mz_uint r_index)
static MZ_FORCEINLINE mz_bool mz_zip_set_error(mz_zip_archive *pZip, mz_zip_error err_num)
mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index)
mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index)
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)
#define TINFL_CR_RETURN(state_index, result)
#define TINFL_CR_RETURN_FOREVER(state_index, result)
mz_zip_error mz_zip_set_last_error(mz_zip_archive *pZip, mz_zip_error err_num)
@ TDEFL_MAX_SUPPORTED_HUFF_CODESIZE
int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
#define MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE
static MZ_FORCEINLINE void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit)
void * mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags)
static MZ_FORCEINLINE mz_bool mz_zip_array_reserve(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_capacity, mz_uint growing)
mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat)
mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags)
static mz_bool mz_zip_locate_file_binary_search(mz_zip_archive *pZip, const char *pFilename, mz_uint32 *pIndex)
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)
mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add, 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)
void tdefl_compressor_free(tdefl_compressor *pComp)
mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip)
unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 :-1]
int mz_inflateEnd(mz_streamp pStream)
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)
static const mz_uint mz_bitmasks[17]
void * mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags)
int mz_deflate(mz_streamp pStream, int flush)
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)
#define MZ_FILE_STAT_STRUCT
static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[]
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)
static mz_bool mz_zip_writer_write_zeros(mz_zip_archive *pZip, mz_uint64 cur_file_ofs, mz_uint32 n)
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)
static MZ_FORCEINLINE mz_bool mz_zip_string_equal(const char *pA, const char *pB, mz_uint len, mz_uint flags)
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)
#define MZ_SWAP_UINT32(a, b)
static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int table_len, int code_size_limit, int static_table)
static const mz_uint8 s_tdefl_large_dist_sym[128]
mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr)
mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags)
void * tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out)
mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len)
mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy)
static mz_bool tdefl_compress_block(tdefl_compressor *d, mz_bool static_block)
static size_t mz_zip_compute_crc32_callback(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n)
static MZ_FORCEINLINE void tdefl_record_match(tdefl_compressor *d, mz_uint match_len, mz_uint match_dist)
#define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index)
static mz_bool mz_zip_writer_update_zip64_extension_block(mz_zip_array *pNew_ext, mz_zip_archive *pZip, const mz_uint8 *pExt, uint32_t ext_len, mz_uint64 *pComp_size, mz_uint64 *pUncomp_size, mz_uint64 *pLocal_header_ofs, mz_uint32 *pDisk_start)
mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *pFile, mz_uint flags)
mz_bool mz_zip_reader_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint64 archive_size, mz_uint flags)
tinfl_decompressor * tinfl_decompressor_alloc()
static mz_bool mz_zip_writer_create_local_dir_header(mz_zip_archive *pZip, mz_uint8 *pDst, mz_uint16 filename_size, mz_uint16 extra_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date)
mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **ppBuf, size_t *pSize)
unsigned char mz_validate_uint16[sizeof(mz_uint16)==2 ? 1 :-1]
static MZ_FORCEINLINE void mz_write_le64(mz_uint8 *p, mz_uint64 v)
mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags)
#define MZ_WRITE_LE64(p, v)
mz_bool mz_zip_writer_init_v2(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags)
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)
mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename)
static mz_bool mz_zip_array_ensure_capacity(mz_zip_archive *pZip, mz_zip_array *pArray, size_t min_new_capacity, mz_uint growing)
mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip)
#define TINFL_SKIP_BITS(state_index, n)
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)
static MZ_FORCEINLINE mz_bool mz_zip_array_resize(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_size, mz_uint growing)
#define TDEFL_RLE_PREV_CODE_SIZE()
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)
mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags)
mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size)
static tdefl_status tdefl_flush_output_buffer(tdefl_compressor *d)
void tinfl_decompressor_free(tinfl_decompressor *pDecomp)
#define TDEFL_PUT_BITS(b, l)
static tdefl_sym_freq * tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq *pSyms0, tdefl_sym_freq *pSyms1)
struct mz_stream_s mz_stream
#define MZ_DEFAULT_WINDOW_BITS
mz_uint8 m_dict[TINFL_LZ_DICT_SIZE]
tinfl_status m_last_status
tinfl_decompressor m_decomp
struct mz_internal_state * state
const unsigned char * next_in
mz_bool m_zip64_has_extended_info_fields
mz_zip_array m_sorted_central_dir_offsets
mz_uint64 m_file_archive_start_ofs
mz_zip_array m_central_dir_offsets
mz_zip_array m_central_dir
mz_uint64 m_cur_archive_file_ofs