1#define MINGW_HAS_SECURE_API 1
43 mz_uint32 i, s1 = (mz_uint32)(adler & 0xffff), s2 = (mz_uint32)(adler >> 16);
44 size_t block_len = buf_len % 5552;
49 for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
51 s1 += ptr[0], s2 += s1;
52 s1 += ptr[1], s2 += s1;
53 s1 += ptr[2], s2 += s1;
54 s1 += ptr[3], s2 += s1;
55 s1 += ptr[4], s2 += s1;
56 s1 += ptr[5], s2 += s1;
57 s1 += ptr[6], s2 += s1;
58 s1 += ptr[7], s2 += s1;
60 for (; i < block_len; ++i)
61 s1 += *ptr++, s2 += s1;
62 s1 %= 65521U, s2 %= 65521U;
66 return (s2 << 16) + s1;
73 static const mz_uint32 s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
74 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c };
75 mz_uint32 crcu32 = (mz_uint32)crc;
82 crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b & 0xF)];
83 crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b >> 4)];
87#elif defined(USE_EXTERNAL_MZCRC)
98 static const mz_uint32 s_crc_table[256] =
100 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535,
101 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD,
102 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D,
103 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
104 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,
105 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C,
106 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC,
107 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
108 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB,
109 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
110 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB,
111 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
112 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA,
113 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE,
114 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,
115 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
116 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409,
117 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
118 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739,
119 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
120 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268,
121 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0,
122 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8,
123 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
124 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,
125 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703,
126 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7,
127 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
128 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE,
129 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
130 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6,
131 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
132 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D,
133 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5,
134 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
135 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
136 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
139 mz_uint32
crc32 = (mz_uint32)crc ^ 0xFFFFFFFF;
140 const mz_uint8 *pByte_buf = (
const mz_uint8 *)ptr;
170 (void)opaque, (
void)items, (void)
size;
171 return MZ_MALLOC(items *
size);
175 (void)opaque, (
void)address;
180 (void)opaque, (
void)address, (void)items, (
void)
size;
181 return MZ_REALLOC(address, items *
size);
189#ifndef MINIZ_NO_ZLIB_APIS
191#ifndef MINIZ_NO_DEFLATE_APIS
200 tdefl_compressor *pComp;
219 pComp = (tdefl_compressor *)pStream->
zalloc(pStream->
opaque, 1,
sizeof(tdefl_compressor));
223 pStream->
state = (
struct mz_internal_state *)pComp;
225 if (
tdefl_init(pComp, NULL, NULL, comp_flags) != TDEFL_STATUS_OKAY)
236 if ((!pStream) || (!pStream->
state) || (!pStream->
zalloc) || (!pStream->
zfree))
239 tdefl_init((tdefl_compressor *)pStream->
state, NULL, NULL, ((tdefl_compressor *)pStream->
state)->m_flags);
245 size_t in_bytes, out_bytes;
246 mz_ulong orig_total_in, orig_total_out;
247 int mz_status =
MZ_OK;
257 if (((tdefl_compressor *)pStream->
state)->m_prev_return_status == TDEFL_STATUS_DONE)
264 tdefl_status defl_status;
269 pStream->
next_in += (mz_uint)in_bytes;
270 pStream->
avail_in -= (mz_uint)in_bytes;
271 pStream->
total_in += (mz_uint)in_bytes;
274 pStream->
next_out += (mz_uint)out_bytes;
275 pStream->
avail_out -= (mz_uint)out_bytes;
276 pStream->
total_out += (mz_uint)out_bytes;
283 else if (defl_status == TDEFL_STATUS_DONE)
292 if ((flush) || (pStream->
total_in != orig_total_in) || (pStream->
total_out != orig_total_out))
308 pStream->
state = NULL;
317 return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5);
327 if ((mz_uint64)(source_len | *pDest_len) > 0xFFFFFFFFU)
331 stream.avail_in = (mz_uint32)source_len;
333 stream.avail_out = (mz_uint32)*pDest_len;
346 *pDest_len =
stream.total_out;
362#ifndef MINIZ_NO_INFLATE_APIS
396 pStream->
state = (
struct mz_internal_state *)pDecomp;
443 mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32;
444 size_t in_bytes, out_bytes, orig_avail_in;
447 if ((!pStream) || (!pStream->
state))
456 decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER;
468 if ((flush ==
MZ_FINISH) && (first_call))
471 decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;
476 pStream->
next_in += (mz_uint)in_bytes;
477 pStream->
avail_in -= (mz_uint)in_bytes;
478 pStream->
total_in += (mz_uint)in_bytes;
480 pStream->
next_out += (mz_uint)out_bytes;
481 pStream->
avail_out -= (mz_uint)out_bytes;
482 pStream->
total_out += (mz_uint)out_bytes;
486 else if (status != TINFL_STATUS_DONE)
495 decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT;
512 out_bytes = TINFL_LZ_DICT_SIZE - pState->
m_dict_ofs;
517 pStream->
next_in += (mz_uint)in_bytes;
518 pStream->
avail_in -= (mz_uint)in_bytes;
519 pStream->
total_in += (mz_uint)in_bytes;
534 else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in))
539 if (status == TINFL_STATUS_DONE)
559 pStream->
state = NULL;
570 if ((mz_uint64)(*pSource_len | *pDest_len) > 0xFFFFFFFFU)
574 stream.avail_in = (mz_uint32)*pSource_len;
576 stream.avail_out = (mz_uint32)*pDest_len;
583 *pSource_len = *pSource_len -
stream.avail_in;
589 *pDest_len =
stream.total_out;
609 {
MZ_OK,
"" }, {
MZ_STREAM_END,
"stream end" }, {
MZ_NEED_DICT,
"need dictionary" }, {
MZ_ERRNO,
"file error" }, {
MZ_STREAM_ERROR,
"stream error" }, {
MZ_DATA_ERROR,
"data error" }, {
MZ_MEM_ERROR,
"out of memory" }, {
MZ_BUF_ERROR,
"buf error" }, {
MZ_VERSION_ERROR,
"version error" }, {
MZ_PARAM_ERROR,
"parameter error" }
612 for (i = 0; i <
sizeof(s_error_descs) /
sizeof(s_error_descs[0]); ++i)
613 if (s_error_descs[i].m_err == err)
614 return s_error_descs[i].m_pDesc;
678#ifndef MINIZ_NO_DEFLATE_APIS
689 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,
690 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,
691 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,
692 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,
693 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,
694 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,
695 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,
696 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
701 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,
702 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,
703 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,
704 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
709 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,
710 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,
711 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,
712 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,
713 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,
714 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,
715 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,
716 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,
717 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,
718 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,
719 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,
720 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
725 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,
726 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,
727 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,
728 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,
729 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,
730 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,
731 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,
732 7, 7, 7, 7, 7, 7, 7, 7
737 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,
738 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,
739 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
744 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,
745 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,
746 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
756 mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2];
759 for (i = 0; i < num_syms; i++)
761 mz_uint freq = pSyms0[i].
m_key;
763 hist[256 + ((freq >> 8) & 0xFF)]++;
765 while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256]))
767 for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8)
769 const mz_uint32 *pHist = &hist[pass << 8];
770 mz_uint offsets[256], cur_ofs = 0;
771 for (i = 0; i < 256; i++)
773 offsets[i] = cur_ofs;
776 for (i = 0; i < num_syms; i++)
777 pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i];
780 pCur_syms = pNew_syms;
790 int root, leaf, next, avbl, used, dpth;
801 for (next = 1; next < n - 1; next++)
803 if (leaf >= n || A[root].m_key < A[leaf].m_key)
806 A[root++].
m_key = (mz_uint16)next;
810 if (leaf >= n || (root < next && A[root].m_key < A[leaf].m_key))
812 A[next].
m_key = (mz_uint16)(A[next].m_key + A[root].m_key);
813 A[root++].
m_key = (mz_uint16)next;
816 A[next].
m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key);
819 for (next = n - 3; next >= 0; next--)
820 A[next].m_key = A[A[next].m_key].m_key + 1;
827 while (root >= 0 && (
int)A[root].m_key == dpth)
834 A[next--].
m_key = (mz_uint16)(dpth);
852 if (code_list_len <= 1)
855 pNum_codes[max_code_size] += pNum_codes[i];
856 for (i = max_code_size; i > 0; i--)
857 total += (((mz_uint32)pNum_codes[i]) << (max_code_size - i));
858 while (total != (1UL << max_code_size))
860 pNum_codes[max_code_size]--;
861 for (i = max_code_size - 1; i > 0; i--)
865 pNum_codes[i + 1] += 2;
876 MZ_CLEAR_ARR(num_codes);
879 for (i = 0; i < table_len; i++)
880 num_codes[d->m_huff_code_sizes[table_num][i]]++;
884 tdefl_sym_freq syms0[TDEFL_MAX_HUFF_SYMBOLS], syms1[TDEFL_MAX_HUFF_SYMBOLS], *pSyms;
885 int num_used_syms = 0;
886 const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0];
887 for (i = 0; i < table_len; i++)
890 syms0[num_used_syms].
m_key = (mz_uint16)pSym_count[i];
897 for (i = 0; i < num_used_syms; i++)
898 num_codes[pSyms[i].m_key]++;
902 MZ_CLEAR_ARR(d->m_huff_code_sizes[table_num]);
903 MZ_CLEAR_ARR(d->m_huff_codes[table_num]);
904 for (i = 1, j = num_used_syms; i <= code_size_limit; i++)
905 for (l = num_codes[i]; l > 0; l--)
906 d->m_huff_code_sizes[table_num][pSyms[--j].
m_sym_index] = (mz_uint8)(i);
910 for (j = 0, i = 2; i <= code_size_limit; i++)
911 next_code[i] = j = ((j + num_codes[i - 1]) << 1);
913 for (i = 0; i < table_len; i++)
915 mz_uint rev_code = 0, code, code_size;
916 if ((code_size = d->m_huff_code_sizes[table_num][i]) == 0)
918 code = next_code[code_size]++;
919 for (l = code_size; l > 0; l--, code >>= 1)
920 rev_code = (rev_code << 1) | (code & 1);
921 d->m_huff_codes[table_num][i] = (mz_uint16)rev_code;
925#define TDEFL_PUT_BITS(b, l) \
930 MZ_ASSERT(bits <= ((1U << len) - 1U)); \
931 d->m_bit_buffer |= (bits << d->m_bits_in); \
932 d->m_bits_in += len; \
933 while (d->m_bits_in >= 8) \
935 if (d->m_pOutput_buf < d->m_pOutput_buf_end) \
936 *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \
937 d->m_bit_buffer >>= 8; \
925#define TDEFL_PUT_BITS(b, l) \ …
943#define TDEFL_RLE_PREV_CODE_SIZE() \
945 if (rle_repeat_count) \
947 if (rle_repeat_count < 3) \
949 d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \
950 while (rle_repeat_count--) \
951 packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \
955 d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); \
956 packed_code_sizes[num_packed_code_sizes++] = 16; \
957 packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \
959 rle_repeat_count = 0; \
943#define TDEFL_RLE_PREV_CODE_SIZE() \ …
963#define TDEFL_RLE_ZERO_CODE_SIZE() \
967 if (rle_z_count < 3) \
969 d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); \
970 while (rle_z_count--) \
971 packed_code_sizes[num_packed_code_sizes++] = 0; \
973 else if (rle_z_count <= 10) \
975 d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); \
976 packed_code_sizes[num_packed_code_sizes++] = 17; \
977 packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \
981 d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); \
982 packed_code_sizes[num_packed_code_sizes++] = 18; \
983 packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \
963#define TDEFL_RLE_ZERO_CODE_SIZE() \ …
989static const 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 };
993 int num_lit_codes, num_dist_codes, num_bit_lengths;
994 mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_index;
995 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;
997 d->m_huff_count[0][256] = 1;
1002 for (num_lit_codes = 286; num_lit_codes > 257; num_lit_codes--)
1003 if (d->m_huff_code_sizes[0][num_lit_codes - 1])
1005 for (num_dist_codes = 30; num_dist_codes > 1; num_dist_codes--)
1006 if (d->m_huff_code_sizes[1][num_dist_codes - 1])
1009 memcpy(code_sizes_to_pack, &d->m_huff_code_sizes[0][0], num_lit_codes);
1010 memcpy(code_sizes_to_pack + num_lit_codes, &d->m_huff_code_sizes[1][0], num_dist_codes);
1011 total_code_sizes_to_pack = num_lit_codes + num_dist_codes;
1012 num_packed_code_sizes = 0;
1014 rle_repeat_count = 0;
1016 memset(&d->m_huff_count[2][0], 0,
sizeof(d->m_huff_count[2][0]) * TDEFL_MAX_HUFF_SYMBOLS_2);
1017 for (i = 0; i < total_code_sizes_to_pack; i++)
1019 mz_uint8 code_size = code_sizes_to_pack[i];
1023 if (++rle_z_count == 138)
1031 if (code_size != prev_code_size)
1034 d->m_huff_count[2][code_size] = (mz_uint16)(d->m_huff_count[2][code_size] + 1);
1035 packed_code_sizes[num_packed_code_sizes++] = code_size;
1037 else if (++rle_repeat_count == 6)
1042 prev_code_size = code_size;
1044 if (rle_repeat_count)
1060 for (num_bit_lengths = 18; num_bit_lengths >= 0; num_bit_lengths--)
1063 num_bit_lengths = MZ_MAX(4, (num_bit_lengths + 1));
1065 for (i = 0; (
int)i < num_bit_lengths; i++)
1068 for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes;)
1070 mz_uint code = packed_code_sizes[packed_code_sizes_index++];
1071 MZ_ASSERT(code < TDEFL_MAX_HUFF_SYMBOLS_2);
1072 TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]);
1074 TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++],
"\02\03\07"[code - 16]);
1081 mz_uint8 *p = &d->m_huff_code_sizes[0][0];
1083 for (i = 0; i <= 143; ++i)
1085 for (; i <= 255; ++i)
1087 for (; i <= 279; ++i)
1089 for (; i <= 287; ++i)
1092 memset(d->m_huff_code_sizes[1], 5, 32);
1100static const mz_uint
mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
1102#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS
1106 mz_uint8 *pLZ_codes;
1107 mz_uint8 *pOutput_buf = d->m_pOutput_buf;
1108 mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf;
1109 mz_uint64 bit_buffer = d->m_bit_buffer;
1110 mz_uint bits_in = d->m_bits_in;
1112#define TDEFL_PUT_BITS_FAST(b, l) \
1114 bit_buffer |= (((mz_uint64)(b)) << bits_in); \
1119 for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1)
1122 flags = *pLZ_codes++ | 0x100;
1126 mz_uint s0, s1, n0, n1, sym, num_extra_bits;
1127 mz_uint match_len = pLZ_codes[0];
1128 mz_uint match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8));
1140 sym = (match_dist < 512) ? s0 : s1;
1141 num_extra_bits = (match_dist < 512) ? n0 : n1;
1143 MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
1144 TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
1145 TDEFL_PUT_BITS_FAST(match_dist &
mz_bitmasks[num_extra_bits], num_extra_bits);
1149 mz_uint lit = *pLZ_codes++;
1150 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1151 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1153 if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
1157 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1158 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1160 if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end))
1164 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1165 TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1170 if (pOutput_buf >= d->m_pOutput_buf_end)
1173 memcpy(pOutput_buf, &bit_buffer,
sizeof(mz_uint64));
1174 pOutput_buf += (bits_in >> 3);
1175 bit_buffer >>= (bits_in & ~7);
1179#undef TDEFL_PUT_BITS_FAST
1181 d->m_pOutput_buf = pOutput_buf;
1183 d->m_bit_buffer = 0;
1187 mz_uint32 n = MZ_MIN(bits_in, 16);
1193 TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
1195 return (d->m_pOutput_buf < d->m_pOutput_buf_end);
1201 mz_uint8 *pLZ_codes;
1204 for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1)
1207 flags = *pLZ_codes++ | 0x100;
1210 mz_uint sym, num_extra_bits;
1211 mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8));
1218 if (match_dist < 512)
1228 MZ_ASSERT(d->m_huff_code_sizes[1][sym]);
1229 TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]);
1234 mz_uint lit = *pLZ_codes++;
1235 MZ_ASSERT(d->m_huff_code_sizes[0][lit]);
1236 TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]);
1240 TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]);
1242 return (d->m_pOutput_buf < d->m_pOutput_buf_end);
1259 mz_uint saved_bit_buf, saved_bits_in;
1260 mz_uint8 *pSaved_output_buf;
1261 mz_bool comp_block_succeeded = MZ_FALSE;
1262 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;
1263 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;
1265 d->m_pOutput_buf = pOutput_buf_start;
1266 d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16;
1268 MZ_ASSERT(!d->m_output_flush_remaining);
1269 d->m_output_flush_ofs = 0;
1270 d->m_output_flush_remaining = 0;
1272 *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left);
1273 d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);
1275 if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index))
1277 const mz_uint8 cmf = 0x78;
1278 mz_uint8 flg, flevel = 3;
1282 for (i = 0; i < mz_un; i++)
1292 header = cmf << 8 | (flevel << 6);
1293 header += 31 - (header % 31);
1294 flg = header & 0xFF;
1302 pSaved_output_buf = d->m_pOutput_buf;
1303 saved_bit_buf = d->m_bit_buffer;
1304 saved_bits_in = d->m_bits_in;
1307 comp_block_succeeded =
tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48));
1310 if (((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) &&
1311 ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size))
1314 d->m_pOutput_buf = pSaved_output_buf;
1315 d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
1321 for (i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF)
1325 for (i = 0; i < d->m_total_lz_bytes; ++i)
1327 TDEFL_PUT_BITS(d->m_dict[(d->m_lz_code_buf_dict_pos + i) & TDEFL_LZ_DICT_SIZE_MASK], 8);
1331 else if (!comp_block_succeeded)
1333 d->m_pOutput_buf = pSaved_output_buf;
1334 d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in;
1340 if (flush == TDEFL_FINISH)
1346 if (d->m_flags & TDEFL_WRITE_ZLIB_HEADER)
1348 mz_uint i, a = d->m_adler32;
1349 for (i = 0; i < 4; i++)
1364 for (i = 2; i; --i, z ^= 0xFFFF)
1371 MZ_ASSERT(d->m_pOutput_buf < d->m_pOutput_buf_end);
1373 memset(&d->m_huff_count[0][0], 0,
sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
1374 memset(&d->m_huff_count[1][0], 0,
sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);
1376 d->m_pLZ_code_buf = d->m_lz_code_buf + 1;
1377 d->m_pLZ_flags = d->m_lz_code_buf;
1378 d->m_num_flags_left = 8;
1379 d->m_lz_code_buf_dict_pos += d->m_total_lz_bytes;
1380 d->m_total_lz_bytes = 0;
1383 if ((n = (
int)(d->m_pOutput_buf - pOutput_buf_start)) != 0)
1385 if (d->m_pPut_buf_func)
1387 *d->m_pIn_buf_size = d->m_pSrc - (
const mz_uint8 *)d->m_pIn_buf;
1388 if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user))
1389 return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED);
1391 else if (pOutput_buf_start == d->m_output_buf)
1393 int bytes_to_copy = (
int)MZ_MIN((
size_t)n, (
size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs));
1394 memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy);
1395 d->m_out_buf_ofs += bytes_to_copy;
1396 if ((n -= bytes_to_copy) != 0)
1398 d->m_output_flush_ofs = bytes_to_copy;
1399 d->m_output_flush_remaining = n;
1404 d->m_out_buf_ofs += n;
1408 return d->m_output_flush_remaining;
1411#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
1412#ifdef MINIZ_UNALIGNED_USE_MEMCPY
1413static mz_uint16 TDEFL_READ_UNALIGNED_WORD(
const mz_uint8* p)
1416 memcpy(&ret, p,
sizeof(mz_uint16));
1419static mz_uint16 TDEFL_READ_UNALIGNED_WORD2(
const mz_uint16* p)
1422 memcpy(&ret, p,
sizeof(mz_uint16));
1426#define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16 *)(p)
1427#define TDEFL_READ_UNALIGNED_WORD2(p) *(const mz_uint16 *)(p)
1429static 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)
1431 mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
1432 mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
1433 const mz_uint16 *s = (
const mz_uint16 *)(d->m_dict + pos), *p, *q;
1434 mz_uint16 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]), s01 = TDEFL_READ_UNALIGNED_WORD2(s);
1435 MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN);
1436 if (max_match_len <= match_len)
1442 if (--num_probes_left == 0)
1444#define TDEFL_PROBE \
1445 next_probe_pos = d->m_next[probe_pos]; \
1446 if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) \
1448 probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
1449 if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) \
1457 q = (
const mz_uint16 *)(d->m_dict + probe_pos);
1458 if (TDEFL_READ_UNALIGNED_WORD2(q) != s01)
1464 }
while ((TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) &&
1465 (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (--probe_len > 0));
1468 *pMatch_dist = dist;
1469 *pMatch_len = MZ_MIN(max_match_len, (mz_uint)TDEFL_MAX_MATCH_LEN);
1472 else if ((probe_len = ((mz_uint)(p - s) * 2) + (mz_uint)(*(
const mz_uint8 *)p == *(
const mz_uint8 *)q)) > match_len)
1474 *pMatch_dist = dist;
1475 if ((*pMatch_len = match_len = MZ_MIN(max_match_len, probe_len)) == max_match_len)
1477 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]);
1482static 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)
1484 mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len;
1485 mz_uint num_probes_left = d->m_max_probes[match_len >= 32];
1486 const mz_uint8 *s = d->m_dict + pos, *p, *q;
1487 mz_uint8 c0 = d->m_dict[pos + match_len], c1 = d->m_dict[pos + match_len - 1];
1488 MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN);
1489 if (max_match_len <= match_len)
1495 if (--num_probes_left == 0)
1497#define TDEFL_PROBE \
1498 next_probe_pos = d->m_next[probe_pos]; \
1499 if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) \
1501 probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \
1502 if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) \
1511 q = d->m_dict + probe_pos;
1512 for (probe_len = 0; probe_len < max_match_len; probe_len++)
1515 if (probe_len > match_len)
1517 *pMatch_dist = dist;
1518 if ((*pMatch_len = match_len = probe_len) == max_match_len)
1520 c0 = d->m_dict[pos + match_len];
1521 c1 = d->m_dict[pos + match_len - 1];
1482static 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) {
…}
1527#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
1528#ifdef MINIZ_UNALIGNED_USE_MEMCPY
1529static mz_uint32 TDEFL_READ_UNALIGNED_WORD32(
const mz_uint8* p)
1532 memcpy(&ret, p,
sizeof(mz_uint32));
1536#define TDEFL_READ_UNALIGNED_WORD32(p) *(const mz_uint32 *)(p)
1538static mz_bool tdefl_compress_fast(tdefl_compressor *d)
1541 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;
1542 mz_uint8 *pLZ_code_buf = d->m_pLZ_code_buf, *pLZ_flags = d->m_pLZ_flags;
1543 mz_uint cur_pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK;
1545 while ((d->m_src_buf_left) || ((d->m_flush) && (lookahead_size)))
1547 const mz_uint TDEFL_COMP_FAST_LOOKAHEAD_SIZE = 4096;
1548 mz_uint dst_pos = (lookahead_pos + lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK;
1549 mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(d->m_src_buf_left, TDEFL_COMP_FAST_LOOKAHEAD_SIZE - lookahead_size);
1550 d->m_src_buf_left -= num_bytes_to_process;
1551 lookahead_size += num_bytes_to_process;
1553 while (num_bytes_to_process)
1555 mz_uint32 n = MZ_MIN(TDEFL_LZ_DICT_SIZE - dst_pos, num_bytes_to_process);
1556 memcpy(d->m_dict + dst_pos, d->m_pSrc, n);
1557 if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
1558 memcpy(d->m_dict + TDEFL_LZ_DICT_SIZE + dst_pos, d->m_pSrc, MZ_MIN(n, (TDEFL_MAX_MATCH_LEN - 1) - dst_pos));
1560 dst_pos = (dst_pos + n) & TDEFL_LZ_DICT_SIZE_MASK;
1561 num_bytes_to_process -= n;
1564 dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - lookahead_size, dict_size);
1565 if ((!d->m_flush) && (lookahead_size < TDEFL_COMP_FAST_LOOKAHEAD_SIZE))
1568 while (lookahead_size >= 4)
1570 mz_uint cur_match_dist, cur_match_len = 1;
1571 mz_uint8 *pCur_dict = d->m_dict + cur_pos;
1572 mz_uint first_trigram = TDEFL_READ_UNALIGNED_WORD32(pCur_dict) & 0xFFFFFF;
1573 mz_uint hash = (first_trigram ^ (first_trigram >> (24 - (TDEFL_LZ_HASH_BITS - 8)))) & TDEFL_LEVEL1_HASH_SIZE_MASK;
1574 mz_uint probe_pos = d->m_hash[hash];
1575 d->m_hash[hash] = (mz_uint16)lookahead_pos;
1577 if (((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((TDEFL_READ_UNALIGNED_WORD32(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram))
1579 const mz_uint16 *p = (
const mz_uint16 *)pCur_dict;
1580 const mz_uint16 *q = (
const mz_uint16 *)(d->m_dict + probe_pos);
1581 mz_uint32 probe_len = 32;
1584 }
while ((TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) &&
1585 (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (TDEFL_READ_UNALIGNED_WORD2(++p) == TDEFL_READ_UNALIGNED_WORD2(++q)) && (--probe_len > 0));
1586 cur_match_len = ((mz_uint)(p - (
const mz_uint16 *)pCur_dict) * 2) + (mz_uint)(*(
const mz_uint8 *)p == *(
const mz_uint8 *)q);
1588 cur_match_len = cur_match_dist ? TDEFL_MAX_MATCH_LEN : 0;
1590 if ((cur_match_len < TDEFL_MIN_MATCH_LEN) || ((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U * 1024U)))
1593 *pLZ_code_buf++ = (mz_uint8)first_trigram;
1594 *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1);
1595 d->m_huff_count[0][(mz_uint8)first_trigram]++;
1600 cur_match_len = MZ_MIN(cur_match_len, lookahead_size);
1602 MZ_ASSERT((cur_match_len >= TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 1) && (cur_match_dist <= TDEFL_LZ_DICT_SIZE));
1606 pLZ_code_buf[0] = (mz_uint8)(cur_match_len - TDEFL_MIN_MATCH_LEN);
1607#ifdef MINIZ_UNALIGNED_USE_MEMCPY
1608 memcpy(&pLZ_code_buf[1], &cur_match_dist,
sizeof(cur_match_dist));
1610 *(mz_uint16 *)(&pLZ_code_buf[1]) = (mz_uint16)cur_match_dist;
1613 *pLZ_flags = (mz_uint8)((*pLZ_flags >> 1) | 0x80);
1617 d->m_huff_count[1][(cur_match_dist < 512) ? s0 : s1]++;
1619 d->m_huff_count[0][
s_tdefl_len_sym[cur_match_len - TDEFL_MIN_MATCH_LEN]]++;
1624 *pLZ_code_buf++ = (mz_uint8)first_trigram;
1625 *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1);
1626 d->m_huff_count[0][(mz_uint8)first_trigram]++;
1629 if (--num_flags_left == 0)
1632 pLZ_flags = pLZ_code_buf++;
1635 total_lz_bytes += cur_match_len;
1636 lookahead_pos += cur_match_len;
1637 dict_size = MZ_MIN(dict_size + cur_match_len, (mz_uint)TDEFL_LZ_DICT_SIZE);
1638 cur_pos = (cur_pos + cur_match_len) & TDEFL_LZ_DICT_SIZE_MASK;
1639 MZ_ASSERT(lookahead_size >= cur_match_len);
1640 lookahead_size -= cur_match_len;
1642 if (pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8])
1645 d->m_lookahead_pos = lookahead_pos;
1646 d->m_lookahead_size = lookahead_size;
1647 d->m_dict_size = dict_size;
1648 d->m_total_lz_bytes = total_lz_bytes;
1649 d->m_pLZ_code_buf = pLZ_code_buf;
1650 d->m_pLZ_flags = pLZ_flags;
1651 d->m_num_flags_left = num_flags_left;
1653 return (n < 0) ? MZ_FALSE : MZ_TRUE;
1654 total_lz_bytes = d->m_total_lz_bytes;
1655 pLZ_code_buf = d->m_pLZ_code_buf;
1656 pLZ_flags = d->m_pLZ_flags;
1657 num_flags_left = d->m_num_flags_left;
1661 while (lookahead_size)
1663 mz_uint8 lit = d->m_dict[cur_pos];
1666 *pLZ_code_buf++ = lit;
1667 *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1);
1668 if (--num_flags_left == 0)
1671 pLZ_flags = pLZ_code_buf++;
1674 d->m_huff_count[0][lit]++;
1677 dict_size = MZ_MIN(dict_size + 1, (mz_uint)TDEFL_LZ_DICT_SIZE);
1678 cur_pos = (cur_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK;
1681 if (pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8])
1684 d->m_lookahead_pos = lookahead_pos;
1685 d->m_lookahead_size = lookahead_size;
1686 d->m_dict_size = dict_size;
1687 d->m_total_lz_bytes = total_lz_bytes;
1688 d->m_pLZ_code_buf = pLZ_code_buf;
1689 d->m_pLZ_flags = pLZ_flags;
1690 d->m_num_flags_left = num_flags_left;
1692 return (n < 0) ? MZ_FALSE : MZ_TRUE;
1693 total_lz_bytes = d->m_total_lz_bytes;
1694 pLZ_code_buf = d->m_pLZ_code_buf;
1695 pLZ_flags = d->m_pLZ_flags;
1696 num_flags_left = d->m_num_flags_left;
1701 d->m_lookahead_pos = lookahead_pos;
1702 d->m_lookahead_size = lookahead_size;
1703 d->m_dict_size = dict_size;
1704 d->m_total_lz_bytes = total_lz_bytes;
1705 d->m_pLZ_code_buf = pLZ_code_buf;
1706 d->m_pLZ_flags = pLZ_flags;
1707 d->m_num_flags_left = num_flags_left;
1714 d->m_total_lz_bytes++;
1715 *d->m_pLZ_code_buf++ = lit;
1716 *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> 1);
1717 if (--d->m_num_flags_left == 0)
1719 d->m_num_flags_left = 8;
1720 d->m_pLZ_flags = d->m_pLZ_code_buf++;
1722 d->m_huff_count[0][lit]++;
1729 MZ_ASSERT((match_len >= TDEFL_MIN_MATCH_LEN) && (match_dist >= 1) && (match_dist <= TDEFL_LZ_DICT_SIZE));
1731 d->m_total_lz_bytes += match_len;
1733 d->m_pLZ_code_buf[0] = (mz_uint8)(match_len - TDEFL_MIN_MATCH_LEN);
1736 d->m_pLZ_code_buf[1] = (mz_uint8)(match_dist & 0xFF);
1737 d->m_pLZ_code_buf[2] = (mz_uint8)(match_dist >> 8);
1738 d->m_pLZ_code_buf += 3;
1740 *d->m_pLZ_flags = (mz_uint8)((*d->m_pLZ_flags >> 1) | 0x80);
1741 if (--d->m_num_flags_left == 0)
1743 d->m_num_flags_left = 8;
1744 d->m_pLZ_flags = d->m_pLZ_code_buf++;
1749 d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++;
1750 d->m_huff_count[0][
s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++;
1755 const mz_uint8 *pSrc = d->m_pSrc;
1756 size_t src_buf_left = d->m_src_buf_left;
1757 tdefl_flush flush = d->m_flush;
1759 while ((src_buf_left) || ((flush) && (d->m_lookahead_size)))
1761 mz_uint len_to_move, cur_match_dist, cur_match_len, cur_pos;
1763 if ((d->m_lookahead_size + d->m_dict_size) >= (TDEFL_MIN_MATCH_LEN - 1))
1765 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;
1766 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];
1767 mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(src_buf_left, TDEFL_MAX_MATCH_LEN - d->m_lookahead_size);
1768 const mz_uint8 *pSrc_end = pSrc ? pSrc + num_bytes_to_process : NULL;
1769 src_buf_left -= num_bytes_to_process;
1770 d->m_lookahead_size += num_bytes_to_process;
1771 while (pSrc != pSrc_end)
1773 mz_uint8 c = *pSrc++;
1774 d->m_dict[dst_pos] = c;
1775 if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
1776 d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c;
1777 hash = ((hash << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1);
1778 d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash];
1779 d->m_hash[hash] = (mz_uint16)(ins_pos);
1780 dst_pos = (dst_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK;
1786 while ((src_buf_left) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN))
1788 mz_uint8 c = *pSrc++;
1789 mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK;
1791 d->m_dict[dst_pos] = c;
1792 if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1))
1793 d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c;
1794 if ((++d->m_lookahead_size + d->m_dict_size) >= TDEFL_MIN_MATCH_LEN)
1796 mz_uint ins_pos = d->m_lookahead_pos + (d->m_lookahead_size - 1) - 2;
1797 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);
1798 d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash];
1799 d->m_hash[hash] = (mz_uint16)(ins_pos);
1803 d->m_dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - d->m_lookahead_size, d->m_dict_size);
1804 if ((!flush) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN))
1810 cur_match_len = d->m_saved_match_len ? d->m_saved_match_len : (TDEFL_MIN_MATCH_LEN - 1);
1811 cur_pos = d->m_lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK;
1812 if (d->m_flags & (TDEFL_RLE_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS))
1814 if ((d->m_dict_size) && (!(d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS)))
1816 mz_uint8 c = d->m_dict[(cur_pos - 1) & TDEFL_LZ_DICT_SIZE_MASK];
1818 while (cur_match_len < d->m_lookahead_size)
1820 if (d->m_dict[cur_pos + cur_match_len] != c)
1824 if (cur_match_len < TDEFL_MIN_MATCH_LEN)
1832 tdefl_find_match(d, d->m_lookahead_pos, d->m_dict_size, d->m_lookahead_size, &cur_match_dist, &cur_match_len);
1834 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)))
1836 cur_match_dist = cur_match_len = 0;
1838 if (d->m_saved_match_len)
1840 if (cur_match_len > d->m_saved_match_len)
1843 if (cur_match_len >= 128)
1846 d->m_saved_match_len = 0;
1847 len_to_move = cur_match_len;
1851 d->m_saved_lit = d->m_dict[cur_pos];
1852 d->m_saved_match_dist = cur_match_dist;
1853 d->m_saved_match_len = cur_match_len;
1859 len_to_move = d->m_saved_match_len - 1;
1860 d->m_saved_match_len = 0;
1863 else if (!cur_match_dist)
1865 else if ((d->m_greedy_parsing) || (d->m_flags & TDEFL_RLE_MATCHES) || (cur_match_len >= 128))
1868 len_to_move = cur_match_len;
1872 d->m_saved_lit = d->m_dict[MZ_MIN(cur_pos,
sizeof(d->m_dict) - 1)];
1873 d->m_saved_match_dist = cur_match_dist;
1874 d->m_saved_match_len = cur_match_len;
1877 d->m_lookahead_pos += len_to_move;
1878 MZ_ASSERT(d->m_lookahead_size >= len_to_move);
1879 d->m_lookahead_size -= len_to_move;
1880 d->m_dict_size = MZ_MIN(d->m_dict_size + len_to_move, (mz_uint)TDEFL_LZ_DICT_SIZE);
1882 if ((d->m_pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) ||
1883 ((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))))
1887 d->m_src_buf_left = src_buf_left;
1889 return (n < 0) ? MZ_FALSE : MZ_TRUE;
1894 d->m_src_buf_left = src_buf_left;
1900 if (d->m_pIn_buf_size)
1902 *d->m_pIn_buf_size = d->m_pSrc - (
const mz_uint8 *)d->m_pIn_buf;
1905 if (d->m_pOut_buf_size)
1907 size_t n = MZ_MIN(*d->m_pOut_buf_size - d->m_out_buf_ofs, d->m_output_flush_remaining);
1908 memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf + d->m_output_flush_ofs, n);
1909 d->m_output_flush_ofs += (mz_uint)n;
1910 d->m_output_flush_remaining -= (mz_uint)n;
1911 d->m_out_buf_ofs += n;
1913 *d->m_pOut_buf_size = d->m_out_buf_ofs;
1916 return (d->m_finished && !d->m_output_flush_remaining) ? TDEFL_STATUS_DONE : TDEFL_STATUS_OKAY;
1919tdefl_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)
1927 return TDEFL_STATUS_BAD_PARAM;
1930 d->m_pIn_buf = pIn_buf;
1931 d->m_pIn_buf_size = pIn_buf_size;
1932 d->m_pOut_buf = pOut_buf;
1933 d->m_pOut_buf_size = pOut_buf_size;
1934 d->m_pSrc = (
const mz_uint8 *)(pIn_buf);
1935 d->m_src_buf_left = pIn_buf_size ? *pIn_buf_size : 0;
1936 d->m_out_buf_ofs = 0;
1939 if (((d->m_pPut_buf_func != NULL) == ((pOut_buf != NULL) || (pOut_buf_size != NULL))) || (d->m_prev_return_status != TDEFL_STATUS_OKAY) ||
1940 (d->m_wants_to_finish && (flush != TDEFL_FINISH)) || (pIn_buf_size && *pIn_buf_size && !pIn_buf) || (pOut_buf_size && *pOut_buf_size && !pOut_buf))
1946 return (d->m_prev_return_status = TDEFL_STATUS_BAD_PARAM);
1948 d->m_wants_to_finish |= (flush == TDEFL_FINISH);
1950 if ((d->m_output_flush_remaining) || (d->m_finished))
1953#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
1954 if (((d->m_flags & TDEFL_MAX_PROBES_MASK) == 1) &&
1955 ((d->m_flags & TDEFL_GREEDY_PARSING_FLAG) != 0) &&
1956 ((d->m_flags & (TDEFL_FILTER_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS | TDEFL_RLE_MATCHES)) == 0))
1958 if (!tdefl_compress_fast(d))
1959 return d->m_prev_return_status;
1965 return d->m_prev_return_status;
1968 if ((d->m_flags & (TDEFL_WRITE_ZLIB_HEADER | TDEFL_COMPUTE_ADLER32)) && (pIn_buf))
1969 d->m_adler32 = (mz_uint32)
mz_adler32(d->m_adler32, (
const mz_uint8 *)pIn_buf, d->m_pSrc - (
const mz_uint8 *)pIn_buf);
1971 if ((flush) && (!d->m_lookahead_size) && (!d->m_src_buf_left) && (!d->m_output_flush_remaining))
1974 return d->m_prev_return_status;
1975 d->m_finished = (flush == TDEFL_FINISH);
1976 if (flush == TDEFL_FULL_FLUSH)
1978 MZ_CLEAR_ARR(d->m_hash);
1979 MZ_CLEAR_ARR(d->m_next);
1919tdefl_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) {
…}
1989 MZ_ASSERT(d->m_pPut_buf_func);
1990 return tdefl_compress(d, pIn_buf, &in_buf_size, NULL, NULL, flush);
1993tdefl_status
tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func,
void *pPut_buf_user,
int flags)
1995 d->m_pPut_buf_func = pPut_buf_func;
1996 d->m_pPut_buf_user = pPut_buf_user;
1997 d->m_flags = (mz_uint)(flags);
1998 d->m_max_probes[0] = 1 + ((flags & 0xFFF) + 2) / 3;
1999 d->m_greedy_parsing = (flags & TDEFL_GREEDY_PARSING_FLAG) != 0;
2000 d->m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3;
2001 if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG))
2002 MZ_CLEAR_ARR(d->m_hash);
2003 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;
2004 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;
2005 d->m_pLZ_code_buf = d->m_lz_code_buf + 1;
2006 d->m_pLZ_flags = d->m_lz_code_buf;
2007 *d->m_pLZ_flags = 0;
2008 d->m_num_flags_left = 8;
2009 d->m_pOutput_buf = d->m_output_buf;
2010 d->m_pOutput_buf_end = d->m_output_buf;
2011 d->m_prev_return_status = TDEFL_STATUS_OKAY;
2012 d->m_saved_match_dist = d->m_saved_match_len = d->m_saved_lit = 0;
2014 d->m_pIn_buf = NULL;
2015 d->m_pOut_buf = NULL;
2016 d->m_pIn_buf_size = NULL;
2017 d->m_pOut_buf_size = NULL;
2018 d->m_flush = TDEFL_NO_FLUSH;
2020 d->m_src_buf_left = 0;
2021 d->m_out_buf_ofs = 0;
2022 if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG))
2023 MZ_CLEAR_ARR(d->m_dict);
2024 memset(&d->m_huff_count[0][0], 0,
sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
2025 memset(&d->m_huff_count[1][0], 0,
sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);
2026 return TDEFL_STATUS_OKAY;
1993tdefl_status
tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func,
void *pPut_buf_user,
int flags) {
…}
2031 return d->m_prev_return_status;
2036 return d->m_adler32;
2041 tdefl_compressor *pComp;
2043 if (((buf_len) && (!pBuf)) || (!pPut_buf_func))
2045 pComp = (tdefl_compressor *)MZ_MALLOC(
sizeof(tdefl_compressor));
2048 succeeded = (
tdefl_init(pComp, pPut_buf_func, pPut_buf_user, flags) == TDEFL_STATUS_OKAY);
2049 succeeded = succeeded && (
tdefl_compress_buffer(pComp, pBuf, buf_len, TDEFL_FINISH) == TDEFL_STATUS_DONE);
2064 size_t new_size = p->
m_size + len;
2073 new_capacity = MZ_MAX(128U, new_capacity << 1U);
2074 }
while (new_size > new_capacity);
2075 pNew_buf = (mz_uint8 *)MZ_REALLOC(p->
m_pBuf, new_capacity);
2089 MZ_CLEAR_OBJ(out_buf);
2097 *pOut_len = out_buf.
m_size;
2104 MZ_CLEAR_OBJ(out_buf);
2107 out_buf.
m_pBuf = (mz_uint8 *)pOut_buf;
2114static const mz_uint
s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
2120 if (window_bits > 0)
2121 comp_flags |= TDEFL_WRITE_ZLIB_HEADER;
2124 comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS;
2126 comp_flags |= TDEFL_FILTER_MATCHES;
2128 comp_flags &= ~TDEFL_MAX_PROBES_MASK;
2130 comp_flags |= TDEFL_FORCE_ALL_STATIC_BLOCKS;
2131 else if (strategy ==
MZ_RLE)
2132 comp_flags |= TDEFL_RLE_MATCHES;
2138#pragma warning(push)
2139#pragma warning(disable : 4204)
2148 static const mz_uint s_tdefl_png_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
2149 tdefl_compressor *pComp = (tdefl_compressor *)MZ_MALLOC(
sizeof(tdefl_compressor));
2151 int i, bpl = w * num_chans,
y, z;
2156 MZ_CLEAR_OBJ(out_buf);
2158 out_buf.
m_capacity = 57 + MZ_MAX(64, (1 + bpl) * h);
2165 for (z = 41; z; --z)
2169 for (
y = 0;
y < h; ++
y)
2181 *pLen_out = out_buf.
m_size - 41;
2183 static const mz_uint8 chans[] = { 0x00, 0x00, 0x04, 0x02, 0x06 };
2184 mz_uint8 pnghdr[41] = { 0x89, 0x50, 0x4e, 0x47, 0x0d,
2185 0x0a, 0x1a, 0x0a, 0x00, 0x00,
2186 0x00, 0x0d, 0x49, 0x48, 0x44,
2187 0x52, 0x00, 0x00, 0x00, 0x00,
2188 0x00, 0x00, 0x00, 0x00, 0x08,
2189 0x00, 0x00, 0x00, 0x00, 0x00,
2190 0x00, 0x00, 0x00, 0x00, 0x00,
2191 0x00, 0x00, 0x49, 0x44, 0x41,
2193 pnghdr[18] = (mz_uint8)(w >> 8);
2194 pnghdr[19] = (mz_uint8)w;
2195 pnghdr[22] = (mz_uint8)(h >> 8);
2196 pnghdr[23] = (mz_uint8)h;
2197 pnghdr[25] = chans[num_chans];
2198 pnghdr[33] = (mz_uint8)(*pLen_out >> 24);
2199 pnghdr[34] = (mz_uint8)(*pLen_out >> 16);
2200 pnghdr[35] = (mz_uint8)(*pLen_out >> 8);
2201 pnghdr[36] = (mz_uint8)*pLen_out;
2203 for (i = 0; i < 4; ++i, c <<= 8)
2204 ((mz_uint8 *)(pnghdr + 29))[i] = (mz_uint8)(c >> 24);
2205 memcpy(out_buf.
m_pBuf, pnghdr, 41);
2216 for (i = 0; i < 4; ++i, c <<= 8)
2217 (out_buf.
m_pBuf + out_buf.
m_size - 16)[i] = (mz_uint8)(c >> 24);
2229#ifndef MINIZ_NO_MALLOC
2235 return (tdefl_compressor *)MZ_MALLOC(
sizeof(tdefl_compressor));
2281#ifndef MINIZ_NO_INFLATE_APIS
2289#define TINFL_MEMCPY(d, s, l) memcpy(d, s, l)
2290#define TINFL_MEMSET(p, c, l) memset(p, c, l)
2292#define TINFL_CR_BEGIN \
2293 switch (r->m_state) \
2292#define TINFL_CR_BEGIN \ …
2296#define TINFL_CR_RETURN(state_index, result) \
2300 r->m_state = state_index; \
2302 case state_index:; \
2296#define TINFL_CR_RETURN(state_index, result) \ …
2305#define TINFL_CR_RETURN_FOREVER(state_index, result) \
2310 TINFL_CR_RETURN(state_index, result); \
2305#define TINFL_CR_RETURN_FOREVER(state_index, result) \ …
2314#define TINFL_CR_FINISH }
2316#define TINFL_GET_BYTE(state_index, c) \
2319 while (pIn_buf_cur >= pIn_buf_end) \
2321 TINFL_CR_RETURN(state_index, (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) ? TINFL_STATUS_NEEDS_MORE_INPUT : TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS); \
2323 c = *pIn_buf_cur++; \
2316#define TINFL_GET_BYTE(state_index, c) \ …
2327#define TINFL_NEED_BITS(state_index, n) \
2331 TINFL_GET_BYTE(state_index, c); \
2332 bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); \
2334 } while (num_bits < (mz_uint)(n))
2327#define TINFL_NEED_BITS(state_index, n) \ …
2335#define TINFL_SKIP_BITS(state_index, n) \
2338 if (num_bits < (mz_uint)(n)) \
2340 TINFL_NEED_BITS(state_index, n); \
2335#define TINFL_SKIP_BITS(state_index, n) \ …
2346#define TINFL_GET_BITS(state_index, b, n) \
2349 if (num_bits < (mz_uint)(n)) \
2351 TINFL_NEED_BITS(state_index, n); \
2353 b = bit_buf & ((1 << (n)) - 1); \
2346#define TINFL_GET_BITS(state_index, b, n) \ …
2363#define TINFL_HUFF_BITBUF_FILL(state_index, pLookUp, pTree) \
2366 temp = pLookUp[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \
2369 code_len = temp >> 9; \
2370 if ((code_len) && (num_bits >= code_len)) \
2373 else if (num_bits > TINFL_FAST_LOOKUP_BITS) \
2375 code_len = TINFL_FAST_LOOKUP_BITS; \
2378 temp = pTree[~temp + ((bit_buf >> code_len++) & 1)]; \
2379 } while ((temp < 0) && (num_bits >= (code_len + 1))); \
2383 TINFL_GET_BYTE(state_index, c); \
2384 bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); \
2386 } while (num_bits < 15);
2363#define TINFL_HUFF_BITBUF_FILL(state_index, pLookUp, pTree) \ …
2394#define TINFL_HUFF_DECODE(state_index, sym, pLookUp, pTree) \
2398 mz_uint code_len, c; \
2399 if (num_bits < 15) \
2401 if ((pIn_buf_end - pIn_buf_cur) < 2) \
2403 TINFL_HUFF_BITBUF_FILL(state_index, pLookUp, pTree); \
2407 bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); \
2412 if ((temp = pLookUp[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
2413 code_len = temp >> 9, temp &= 511; \
2416 code_len = TINFL_FAST_LOOKUP_BITS; \
2419 temp = pTree[~temp + ((bit_buf >> code_len++) & 1)]; \
2420 } while (temp < 0); \
2423 bit_buf >>= code_len; \
2424 num_bits -= code_len; \
2394#define TINFL_HUFF_DECODE(state_index, sym, pLookUp, pTree) \ …
2431 MZ_CLEAR_ARR(r->m_tree_0);
2432 else if (r->m_type == 1)
2433 MZ_CLEAR_ARR(r->m_tree_1);
2435 MZ_CLEAR_ARR(r->m_tree_2);
2438tinfl_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)
2440 static const mz_uint16 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 };
2441 static const mz_uint8 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 };
2442 static const mz_uint16 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 };
2443 static const mz_uint8 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 };
2444 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 };
2445 static const mz_uint16 s_min_table_sizes[3] = { 257, 1, 4 };
2447 mz_int16 *pTrees[3];
2448 mz_uint8 *pCode_sizes[3];
2450 tinfl_status status = TINFL_STATUS_FAILED;
2451 mz_uint32 num_bits, dist, counter, num_extra;
2452 tinfl_bit_buf_t bit_buf;
2453 const mz_uint8 *pIn_buf_cur = pIn_buf_next, *
const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
2454 mz_uint8 *pOut_buf_cur = pOut_buf_next, *
const pOut_buf_end = pOut_buf_next ? pOut_buf_next + *pOut_buf_size : NULL;
2455 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;
2458 if ((!pOut_buf_start) || (!pOut_buf_next) || (!pIn_buf_size) || (!pOut_buf_size))
2460 return TINFL_STATUS_BAD_PARAM;
2462 if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start))
2464 *pIn_buf_size = *pOut_buf_size = 0;
2465 return TINFL_STATUS_BAD_PARAM;
2468 pTrees[0] = r->m_tree_0;
2469 pTrees[1] = r->m_tree_1;
2470 pTrees[2] = r->m_tree_2;
2471 pCode_sizes[0] = r->m_code_size_0;
2472 pCode_sizes[1] = r->m_code_size_1;
2473 pCode_sizes[2] = r->m_code_size_2;
2475 num_bits = r->m_num_bits;
2476 bit_buf = r->m_bit_buf;
2478 counter = r->m_counter;
2479 num_extra = r->m_num_extra;
2480 dist_from_out_buf_start = r->m_dist_from_out_buf_start;
2483 bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0;
2484 r->m_z_adler32 = r->m_check_adler32 = 1;
2485 if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
2489 counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
2490 if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
2491 counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)((size_t)1 << (8U + (r->m_zhdr0 >> 4)))));
2501 r->m_type = r->m_final >> 1;
2505 for (counter = 0; counter < 4; ++counter)
2512 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))))
2516 while ((counter) && (num_bits))
2519 while (pOut_buf_cur >= pOut_buf_end)
2523 *pOut_buf_cur++ = (mz_uint8)dist;
2529 while (pOut_buf_cur >= pOut_buf_end)
2533 while (pIn_buf_cur >= pIn_buf_end)
2535 TINFL_CR_RETURN(38, (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) ? TINFL_STATUS_NEEDS_MORE_INPUT : TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS);
2537 n = MZ_MIN(MZ_MIN((
size_t)(pOut_buf_end - pOut_buf_cur), (
size_t)(pIn_buf_end - pIn_buf_cur)), counter);
2541 counter -= (mz_uint)n;
2544 else if (r->m_type == 3)
2552 mz_uint8 *p = r->m_code_size_0;
2554 r->m_table_sizes[0] = 288;
2555 r->m_table_sizes[1] = 32;
2557 for (i = 0; i <= 143; ++i)
2559 for (; i <= 255; ++i)
2561 for (; i <= 279; ++i)
2563 for (; i <= 287; ++i)
2568 for (counter = 0; counter < 3; counter++)
2570 TINFL_GET_BITS(11, r->m_table_sizes[counter],
"\05\05\04"[counter]);
2571 r->m_table_sizes[counter] += s_min_table_sizes[counter];
2573 MZ_CLEAR_ARR(r->m_code_size_2);
2574 for (counter = 0; counter < r->m_table_sizes[2]; counter++)
2578 r->m_code_size_2[s_length_dezigzag[counter]] = (mz_uint8)s;
2580 r->m_table_sizes[2] = 19;
2582 for (; (
int)r->m_type >= 0; r->m_type--)
2584 int tree_next, tree_cur;
2587 mz_uint8 *pCode_size;
2588 mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16];
2589 pLookUp = r->m_look_up[r->m_type];
2590 pTree = pTrees[r->m_type];
2591 pCode_size = pCode_sizes[r->m_type];
2592 MZ_CLEAR_ARR(total_syms);
2595 for (i = 0; i < r->m_table_sizes[r->m_type]; ++i)
2596 total_syms[pCode_size[i]]++;
2597 used_syms = 0, total = 0;
2598 next_code[0] = next_code[1] = 0;
2599 for (i = 1; i <= 15; ++i)
2601 used_syms += total_syms[i];
2602 next_code[i + 1] = (total = ((total + total_syms[i]) << 1));
2604 if ((65536 != total) && (used_syms > 1))
2608 for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index)
2610 mz_uint rev_code = 0, l, cur_code, code_size = pCode_size[sym_index];
2613 cur_code = next_code[code_size]++;
2614 for (l = code_size; l > 0; l--, cur_code >>= 1)
2615 rev_code = (rev_code << 1) | (cur_code & 1);
2616 if (code_size <= TINFL_FAST_LOOKUP_BITS)
2618 mz_int16 k = (mz_int16)((code_size << 9) | sym_index);
2619 while (rev_code < TINFL_FAST_LOOKUP_SIZE)
2621 pLookUp[rev_code] = k;
2622 rev_code += (1 << code_size);
2626 if (0 == (tree_cur = pLookUp[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)]))
2628 pLookUp[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next;
2629 tree_cur = tree_next;
2632 rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
2633 for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--)
2635 tree_cur -= ((rev_code >>= 1) & 1);
2636 if (!pTree[-tree_cur - 1])
2638 pTree[-tree_cur - 1] = (mz_int16)tree_next;
2639 tree_cur = tree_next;
2643 tree_cur = pTree[-tree_cur - 1];
2645 tree_cur -= ((rev_code >>= 1) & 1);
2646 pTree[-tree_cur - 1] = (mz_int16)sym_index;
2650 for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]);)
2656 r->m_len_codes[counter++] = (mz_uint8)dist;
2659 if ((dist == 16) && (!counter))
2663 num_extra =
"\02\03\07"[dist - 16];
2665 s +=
"\03\03\013"[dist - 16];
2666 TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s);
2669 if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter)
2673 TINFL_MEMCPY(r->m_code_size_0, r->m_len_codes, r->m_table_sizes[0]);
2674 TINFL_MEMCPY(r->m_code_size_1, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
2682 if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2))
2687 while (pOut_buf_cur >= pOut_buf_end)
2691 *pOut_buf_cur++ = (mz_uint8)counter;
2697#if TINFL_USE_64BIT_BITBUF
2700 bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits);
2707 bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits);
2712 if ((sym2 = r->m_look_up[0][bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
2713 code_len = sym2 >> 9;
2716 code_len = TINFL_FAST_LOOKUP_BITS;
2719 sym2 = r->m_tree_0[~sym2 + ((bit_buf >> code_len++) & 1)];
2723 bit_buf >>= code_len;
2724 num_bits -= code_len;
2728#if !TINFL_USE_64BIT_BITBUF
2731 bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits);
2736 if ((sym2 = r->m_look_up[0][bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
2737 code_len = sym2 >> 9;
2740 code_len = TINFL_FAST_LOOKUP_BITS;
2743 sym2 = r->m_tree_0[~sym2 + ((bit_buf >> code_len++) & 1)];
2746 bit_buf >>= code_len;
2747 num_bits -= code_len;
2749 pOut_buf_cur[0] = (mz_uint8)counter;
2756 pOut_buf_cur[1] = (mz_uint8)sym2;
2760 if ((counter &= 511) == 256)
2763 num_extra = s_length_extra[counter - 257];
2764 counter = s_length_base[counter - 257];
2769 counter += extra_bits;
2773 num_extra = s_dist_extra[dist];
2774 dist = s_dist_base[dist];
2782 dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start;
2783 if ((dist == 0 || dist > dist_from_out_buf_start || dist_from_out_buf_start == 0) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
2788 pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask);
2790 if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end)
2794 while (pOut_buf_cur >= pOut_buf_end)
2798 *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask];
2802#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES
2803 else if ((counter >= 9) && (counter <= dist))
2805 const mz_uint8 *pSrc_end = pSrc + (counter & ~7);
2808#ifdef MINIZ_UNALIGNED_USE_MEMCPY
2809 memcpy(pOut_buf_cur, pSrc,
sizeof(mz_uint32)*2);
2811 ((mz_uint32 *)pOut_buf_cur)[0] = ((
const mz_uint32 *)pSrc)[0];
2812 ((mz_uint32 *)pOut_buf_cur)[1] = ((
const mz_uint32 *)pSrc)[1];
2815 }
while ((pSrc += 8) < pSrc_end);
2816 if ((counter &= 7) < 3)
2820 pOut_buf_cur[0] = pSrc[0];
2822 pOut_buf_cur[1] = pSrc[1];
2823 pOut_buf_cur += counter;
2831 pOut_buf_cur[0] = pSrc[0];
2832 pOut_buf_cur[1] = pSrc[1];
2833 pOut_buf_cur[2] = pSrc[2];
2840 pOut_buf_cur[0] = pSrc[0];
2842 pOut_buf_cur[1] = pSrc[1];
2843 pOut_buf_cur += counter;
2847 }
while (!(r->m_final & 1));
2852 while ((pIn_buf_cur > pIn_buf_next) && (num_bits >= 8))
2857 bit_buf &= ~(~(tinfl_bit_buf_t)0 << num_bits);
2858 MZ_ASSERT(!num_bits);
2860 if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
2862 for (counter = 0; counter < 4; ++counter)
2869 r->m_z_adler32 = (r->m_z_adler32 << 8) | s;
2880 if ((status != TINFL_STATUS_NEEDS_MORE_INPUT) && (status != TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS))
2882 while ((pIn_buf_cur > pIn_buf_next) && (num_bits >= 8))
2888 r->m_num_bits = num_bits;
2889 r->m_bit_buf = bit_buf & ~(~(tinfl_bit_buf_t)0 << num_bits);
2891 r->m_counter = counter;
2892 r->m_num_extra = num_extra;
2893 r->m_dist_from_out_buf_start = dist_from_out_buf_start;
2894 *pIn_buf_size = pIn_buf_cur - pIn_buf_next;
2895 *pOut_buf_size = pOut_buf_cur - pOut_buf_next;
2896 if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0))
2898 const mz_uint8 *ptr = pOut_buf_next;
2899 size_t buf_len = *pOut_buf_size;
2900 mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16;
2901 size_t block_len = buf_len % 5552;
2904 for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
2906 s1 += ptr[0], s2 += s1;
2907 s1 += ptr[1], s2 += s1;
2908 s1 += ptr[2], s2 += s1;
2909 s1 += ptr[3], s2 += s1;
2910 s1 += ptr[4], s2 += s1;
2911 s1 += ptr[5], s2 += s1;
2912 s1 += ptr[6], s2 += s1;
2913 s1 += ptr[7], s2 += s1;
2915 for (; i < block_len; ++i)
2916 s1 += *ptr++, s2 += s1;
2917 s1 %= 65521U, s2 %= 65521U;
2918 buf_len -= block_len;
2921 r->m_check_adler32 = (s2 << 16) + s1;
2922 if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32))
2923 status = TINFL_STATUS_ADLER32_MISMATCH;
2438tinfl_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) {
…}
2931 tinfl_decompressor decomp;
2932 void *pBuf = NULL, *pNew_buf;
2933 size_t src_buf_ofs = 0, out_buf_capacity = 0;
2935 tinfl_init(&decomp);
2938 size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity;
2939 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,
2940 (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
2941 if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT))
2947 src_buf_ofs += src_buf_size;
2948 *pOut_len += dst_buf_size;
2949 if (status == TINFL_STATUS_DONE)
2951 new_out_buf_capacity = out_buf_capacity * 2;
2952 if (new_out_buf_capacity < 128)
2953 new_out_buf_capacity = 128;
2954 pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity);
2962 out_buf_capacity = new_out_buf_capacity;
2969 tinfl_decompressor decomp;
2970 tinfl_status status;
2971 tinfl_init(&decomp);
2972 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);
2973 return (status != TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len;
2979 tinfl_decompressor decomp;
2980 mz_uint8 *pDict = (mz_uint8 *)MZ_MALLOC(TINFL_LZ_DICT_SIZE);
2981 size_t in_buf_ofs = 0, dict_ofs = 0;
2983 return TINFL_STATUS_FAILED;
2984 memset(pDict,0,TINFL_LZ_DICT_SIZE);
2985 tinfl_init(&decomp);
2988 size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs;
2989 tinfl_status status =
tinfl_decompress(&decomp, (
const mz_uint8 *)pIn_buf + in_buf_ofs, &in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size,
2990 (flags & ~(TINFL_FLAG_HAS_MORE_INPUT | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)));
2991 in_buf_ofs += in_buf_size;
2992 if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (
int)dst_buf_size, pPut_buf_user)))
2994 if (status != TINFL_STATUS_HAS_MORE_OUTPUT)
2996 result = (status == TINFL_STATUS_DONE);
2999 dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1);
3002 *pIn_buf_size = in_buf_ofs;
3006#ifndef MINIZ_NO_MALLOC
3009 tinfl_decompressor *pDecomp = (tinfl_decompressor *)MZ_MALLOC(
sizeof(tinfl_decompressor));
3011 tinfl_init(pDecomp);
3054#ifndef MINIZ_NO_ARCHIVE_APIS
3062#ifdef MINIZ_NO_STDIO
3063#define MZ_FILE void *
3065#include <sys/stat.h>
3067#if defined(_MSC_VER) || defined(__MINGW64__) || defined(__MINGW32__)
3069#define WIN32_LEAN_AND_MEAN
3072static WCHAR* mz_utf8z_to_widechar(
const char* str)
3074 int reqChars = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
3075 WCHAR* wStr = (WCHAR*)malloc(reqChars *
sizeof(WCHAR));
3076 MultiByteToWideChar(CP_UTF8, 0, str, -1, wStr, reqChars);
3080static FILE *mz_fopen(
const char *pFilename,
const char *pMode)
3082 WCHAR* wFilename = mz_utf8z_to_widechar(pFilename);
3083 WCHAR* wMode = mz_utf8z_to_widechar(pMode);
3085 errno_t err = _wfopen_s(&pFile, wFilename, wMode);
3088 return err ? NULL : pFile;
3091static FILE *mz_freopen(
const char *pPath,
const char *pMode, FILE *pStream)
3093 WCHAR* wPath = mz_utf8z_to_widechar(pPath);
3094 WCHAR* wMode = mz_utf8z_to_widechar(pMode);
3096 errno_t err = _wfreopen_s(&pFile, wPath, wMode, pStream);
3099 return err ? NULL : pFile;
3102#if defined(__MINGW32__)
3103static int mz_stat(
const char *path,
struct _stat *buffer)
3105 WCHAR* wPath = mz_utf8z_to_widechar(path);
3106 int res = _wstat(wPath, buffer);
3111static int mz_stat64(
const char *path,
struct __stat64 *buffer)
3113 WCHAR* wPath = mz_utf8z_to_widechar(path);
3114 int res = _wstat64(wPath, buffer);
3120#ifndef MINIZ_NO_TIME
3121#include <sys/utime.h>
3123#define MZ_FOPEN mz_fopen
3124#define MZ_FCLOSE fclose
3125#define MZ_FREAD fread
3126#define MZ_FWRITE fwrite
3127#define MZ_FTELL64 _ftelli64
3128#define MZ_FSEEK64 _fseeki64
3129#if defined(__MINGW32__)
3130#define MZ_FILE_STAT_STRUCT _stat
3131#define MZ_FILE_STAT mz_stat
3133#define MZ_FILE_STAT_STRUCT _stat64
3134#define MZ_FILE_STAT mz_stat64
3136#define MZ_FFLUSH fflush
3137#define MZ_FREOPEN mz_freopen
3138#define MZ_DELETE_FILE remove
3140#elif defined(__WATCOMC__)
3141#ifndef MINIZ_NO_TIME
3142#include <sys/utime.h>
3144#define MZ_FOPEN(f, m) fopen(f, m)
3145#define MZ_FCLOSE fclose
3146#define MZ_FREAD fread
3147#define MZ_FWRITE fwrite
3148#define MZ_FTELL64 _ftelli64
3149#define MZ_FSEEK64 _fseeki64
3150#define MZ_FILE_STAT_STRUCT stat
3151#define MZ_FILE_STAT stat
3152#define MZ_FFLUSH fflush
3153#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
3154#define MZ_DELETE_FILE remove
3156#elif defined(__TINYC__)
3157#ifndef MINIZ_NO_TIME
3158#include <sys/utime.h>
3160#define MZ_FOPEN(f, m) fopen(f, m)
3161#define MZ_FCLOSE fclose
3162#define MZ_FREAD fread
3163#define MZ_FWRITE fwrite
3164#define MZ_FTELL64 ftell
3165#define MZ_FSEEK64 fseek
3166#define MZ_FILE_STAT_STRUCT stat
3167#define MZ_FILE_STAT stat
3168#define MZ_FFLUSH fflush
3169#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
3170#define MZ_DELETE_FILE remove
3172#elif defined(__USE_LARGEFILE64)
3173#ifndef MINIZ_NO_TIME
3176#define MZ_FOPEN(f, m) fopen64(f, m)
3177#define MZ_FCLOSE fclose
3178#define MZ_FREAD fread
3179#define MZ_FWRITE fwrite
3180#define MZ_FTELL64 ftello64
3181#define MZ_FSEEK64 fseeko64
3182#define MZ_FILE_STAT_STRUCT stat64
3183#define MZ_FILE_STAT stat64
3184#define MZ_FFLUSH fflush
3185#define MZ_FREOPEN(p, m, s) freopen64(p, m, s)
3186#define MZ_DELETE_FILE remove
3188#elif defined(__APPLE__) || defined(__FreeBSD__)
3189#ifndef MINIZ_NO_TIME
3192#define MZ_FOPEN(f, m) fopen(f, m)
3193#define MZ_FCLOSE fclose
3194#define MZ_FREAD fread
3195#define MZ_FWRITE fwrite
3196#define MZ_FTELL64 ftello
3197#define MZ_FSEEK64 fseeko
3198#define MZ_FILE_STAT_STRUCT stat
3199#define MZ_FILE_STAT stat
3200#define MZ_FFLUSH fflush
3201#define MZ_FREOPEN(p, m, s) freopen(p, m, s)
3202#define MZ_DELETE_FILE remove
3205#pragma message("Using fopen, ftello, fseeko, stat() etc. path for file I/O - this path may not support large files.")
3206#ifndef MINIZ_NO_TIME
3209#define MZ_FOPEN(f, m) fopen(f, m)
3210#define MZ_FCLOSE fclose
3211#define MZ_FREAD fread
3212#define MZ_FWRITE fwrite
3213#ifdef __STRICT_ANSI__
3214#define MZ_FTELL64 ftell
3215#define MZ_FSEEK64 fseek
3217#define MZ_FTELL64 ftello
3218#define MZ_FSEEK64 fseeko
3220#define MZ_FILE_STAT_STRUCT stat
3221#define MZ_FILE_STAT stat
3222#define MZ_FFLUSH fflush
3223#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
3224#define MZ_DELETE_FILE remove
3228#define MZ_TOLOWER(c) ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c))
3351#define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size) (array_ptr)->m_element_size = element_size
3353#if defined(DEBUG) || defined(_DEBUG)
3354static MZ_FORCEINLINE mz_uint mz_zip_array_range_check(
const mz_zip_array *pArray, mz_uint index)
3356 MZ_ASSERT(index < pArray->m_size);
3359#define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[mz_zip_array_range_check(array_ptr, index)]
3361#define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[index]
3372 pZip->m_pFree(pZip->m_pAlloc_opaque, pArray->
m_p);
3379 size_t new_capacity = min_new_capacity;
3385 new_capacity = MZ_MAX(1, pArray->
m_capacity);
3386 while (new_capacity < min_new_capacity)
3389 if (NULL == (pNew_p = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pArray->
m_p, pArray->
m_element_size, new_capacity)))
3391 pArray->
m_p = pNew_p;
3413 pArray->
m_size = new_size;
3424 size_t orig_size = pArray->
m_size;
3432#ifndef MINIZ_NO_TIME
3436 memset(&tm, 0,
sizeof(tm));
3438 tm.tm_year = ((dos_date >> 9) & 127) + 1980 - 1900;
3439 tm.tm_mon = ((dos_date >> 5) & 15) - 1;
3440 tm.tm_mday = dos_date & 31;
3441 tm.tm_hour = (dos_time >> 11) & 31;
3442 tm.tm_min = (dos_time >> 5) & 63;
3443 tm.tm_sec = (dos_time << 1) & 62;
3447#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
3451 struct tm tm_struct;
3452 struct tm *tm = &tm_struct;
3453 errno_t err = localtime_s(tm, &time);
3461 struct tm *tm = localtime(&time);
3464 *pDOS_time = (mz_uint16)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) + ((tm->tm_sec) >> 1));
3465 *pDOS_date = (mz_uint16)(((tm->tm_year + 1900 - 1980) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday);
3469#ifndef MINIZ_NO_STDIO
3470#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
3479 *pTime = file_stat.st_mtime;
3489 memset(&t, 0,
sizeof(t));
3490 t.actime = access_time;
3491 t.modtime = modified_time;
3493 return !utime(pFilename, &t);
3501 pZip->m_last_error = err_num;
3508 if ((!pZip) || (pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID))
3511 if (!pZip->m_pAlloc)
3515 if (!pZip->m_pRealloc)
3518 pZip->m_archive_size = 0;
3519 pZip->m_central_directory_file_ofs = 0;
3520 pZip->m_total_files = 0;
3521 pZip->m_last_error = MZ_ZIP_NO_ERROR;
3523 if (NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1,
sizeof(mz_zip_internal_state))))
3526 memset(pZip->m_pState, 0,
sizeof(mz_zip_internal_state));
3530 pZip->m_pState->m_init_flags = flags;
3531 pZip->m_pState->m_zip64 = MZ_FALSE;
3532 pZip->m_pState->m_zip64_has_extended_info_fields = MZ_FALSE;
3534 pZip->m_zip_mode = MZ_ZIP_MODE_READING;
3544 mz_uint8 l = 0, r = 0;
3547 pE = pL + MZ_MIN(l_len, r_len);
3555 return (pL == pE) ? (l_len < r_len) : (l < r);
3558#define MZ_SWAP_UINT32(a, b) \
3558#define MZ_SWAP_UINT32(a, b) \ …
3570 mz_zip_internal_state *pState = pZip->m_pState;
3571 const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets;
3572 const mz_zip_array *pCentral_dir = &pState->m_central_dir;
3573 mz_uint32 *pIndices;
3574 mz_uint32 start, end;
3575 const mz_uint32
size = pZip->m_total_files;
3582 start = (
size - 2U) >> 1U;
3585 mz_uint64 child, root = start;
3588 if ((child = (root << 1U) + 1U) >=
size)
3604 mz_uint64 child, root = 0;
3608 if ((child = (root << 1U) + 1U) >= end)
3610 child += (((child + 1U) < end) &&
mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1U]));
3622 mz_int64 cur_file_ofs;
3623 mz_uint32 buf_u32[4096 /
sizeof(mz_uint32)];
3624 mz_uint8 *pBuf = (mz_uint8 *)buf_u32;
3627 if (pZip->m_archive_size < record_size)
3631 cur_file_ofs = MZ_MAX((mz_int64)pZip->m_archive_size - (mz_int64)
sizeof(buf_u32), 0);
3634 int i, n = (
int)MZ_MIN(
sizeof(buf_u32), pZip->m_archive_size - cur_file_ofs);
3636 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, n) != (mz_uint)n)
3639 for (i = n - 4; i >= 0; --i)
3641 mz_uint s = MZ_READ_LE32(pBuf + i);
3642 if (s == record_sig)
3644 if ((pZip->m_archive_size - (cur_file_ofs + i)) >= record_size)
3656 if ((!cur_file_ofs) || ((pZip->m_archive_size - cur_file_ofs) >= ((mz_uint64)(MZ_UINT16_MAX) + record_size)))
3659 cur_file_ofs = MZ_MAX(cur_file_ofs - (
sizeof(buf_u32) - 3), 0);
3662 *pOfs = cur_file_ofs;
3668 mz_uint cdir_size = 0, cdir_entries_on_this_disk = 0, num_this_disk = 0, cdir_disk_index = 0;
3669 mz_uint64 cdir_ofs = 0;
3670 mz_int64 cur_file_ofs = 0;
3673 mz_uint32 buf_u32[4096 /
sizeof(mz_uint32)];
3674 mz_uint8 *pBuf = (mz_uint8 *)buf_u32;
3675 mz_bool sort_central_dir = ((flags & MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY) == 0);
3677 mz_uint8 *pZip64_locator = (mz_uint8 *)zip64_end_of_central_dir_locator_u32;
3680 mz_uint8 *pZip64_end_of_central_dir = (mz_uint8 *)zip64_end_of_central_dir_header_u32;
3682 mz_uint64 zip64_end_of_central_dir_ofs = 0;
3712 pZip->m_pState->m_zip64 = MZ_TRUE;
3726 if (pZip->m_pState->m_zip64)
3737 if (zip64_total_num_of_disks != 1U)
3741 if (zip64_cdir_total_entries > MZ_UINT32_MAX)
3744 pZip->m_total_files = (mz_uint32)zip64_cdir_total_entries;
3746 if (zip64_cdir_total_entries_on_this_disk > MZ_UINT32_MAX)
3749 cdir_entries_on_this_disk = (mz_uint32)zip64_cdir_total_entries_on_this_disk;
3752 if (zip64_size_of_central_directory > MZ_UINT32_MAX)
3755 cdir_size = (mz_uint32)zip64_size_of_central_directory;
3764 if (pZip->m_total_files != cdir_entries_on_this_disk)
3767 if (((num_this_disk | cdir_disk_index) != 0) && ((num_this_disk != 1) || (cdir_disk_index != 1)))
3773 if ((cdir_ofs + (mz_uint64)cdir_size) > pZip->m_archive_size)
3776 pZip->m_central_directory_file_ofs = cdir_ofs;
3778 if (pZip->m_total_files)
3783 (!
mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir_offsets, pZip->m_total_files, MZ_FALSE)))
3786 if (sort_central_dir)
3788 if (!
mz_zip_array_resize(pZip, &pZip->m_pState->m_sorted_central_dir_offsets, pZip->m_total_files, MZ_FALSE))
3792 if (pZip->m_pRead(pZip->m_pIO_opaque, cdir_ofs, pZip->m_pState->m_central_dir.m_p, cdir_size) != cdir_size)
3796 p = (
const mz_uint8 *)pZip->m_pState->m_central_dir.m_p;
3797 for (n = cdir_size, i = 0; i < pZip->m_total_files; ++i)
3799 mz_uint total_header_size, disk_index, bit_flags, filename_size, ext_data_size;
3800 mz_uint64 comp_size, decomp_size, local_header_ofs;
3805 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);
3807 if (sort_central_dir)
3816 if ((!pZip->m_pState->m_zip64_has_extended_info_fields) &&
3818 (MZ_MAX(MZ_MAX(comp_size, decomp_size), local_header_ofs) == MZ_UINT32_MAX))
3821 mz_uint32 extra_size_remaining = ext_data_size;
3823 if (extra_size_remaining)
3825 const mz_uint8 *pExtra_data;
3830 buf = MZ_MALLOC(ext_data_size);
3840 pExtra_data = (mz_uint8*)
buf;
3850 mz_uint32 field_data_size;
3852 if (extra_size_remaining < (
sizeof(mz_uint16) * 2))
3858 field_id = MZ_READ_LE16(pExtra_data);
3859 field_data_size = MZ_READ_LE16(pExtra_data +
sizeof(mz_uint16));
3861 if ((field_data_size +
sizeof(mz_uint16) * 2) > extra_size_remaining)
3870 pZip->m_pState->m_zip64 = MZ_TRUE;
3871 pZip->m_pState->m_zip64_has_extended_info_fields = MZ_TRUE;
3875 pExtra_data +=
sizeof(mz_uint16) * 2 + field_data_size;
3876 extra_size_remaining = extra_size_remaining -
sizeof(mz_uint16) * 2 - field_data_size;
3877 }
while (extra_size_remaining);
3884 if ((comp_size != MZ_UINT32_MAX) && (decomp_size != MZ_UINT32_MAX))
3886 if (((!MZ_READ_LE32(p +
MZ_ZIP_CDH_METHOD_OFS)) && (decomp_size != comp_size)) || (decomp_size && !comp_size))
3891 if ((disk_index == MZ_UINT16_MAX) || ((disk_index != num_this_disk) && (disk_index != 1)))
3894 if (comp_size != MZ_UINT32_MAX)
3907 n -= total_header_size;
3908 p += total_header_size;
3912 if (sort_central_dir)
3926 mz_bool status = MZ_TRUE;
3931 if ((!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
3934 pZip->m_last_error = MZ_ZIP_INVALID_PARAMETER;
3941 mz_zip_internal_state *pState = pZip->m_pState;
3942 pZip->m_pState = NULL;
3948#ifndef MINIZ_NO_STDIO
3949 if (pState->m_pFile)
3951 if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE)
3956 pZip->m_last_error = MZ_ZIP_FILE_CLOSE_FAILED;
3960 pState->m_pFile = NULL;
3964 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
3966 pZip->m_zip_mode = MZ_ZIP_MODE_INVALID;
3977 if ((!pZip) || (!pZip->m_pRead))
3983 pZip->m_zip_type = MZ_ZIP_TYPE_USER;
3984 pZip->m_archive_size =
size;
3997 mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
3998 size_t s = (file_ofs >= pZip->m_archive_size) ? 0 : (size_t)MZ_MIN(pZip->m_archive_size - file_ofs, n);
3999 memcpy(pBuf, (
const mz_uint8 *)pZip->m_pState->m_pMem + file_ofs, s);
4014 pZip->m_zip_type = MZ_ZIP_TYPE_MEMORY;
4015 pZip->m_archive_size =
size;
4017 pZip->m_pIO_opaque = pZip;
4018 pZip->m_pNeeds_keepalive = NULL;
4021 pZip->m_pState->m_pMem =
const_cast<void *
>(pMem);
4023 pZip->m_pState->m_pMem = (
void *)pMem;
4026 pZip->m_pState->m_mem_size =
size;
4037#ifndef MINIZ_NO_STDIO
4040 mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
4041 mz_int64 cur_ofs =
MZ_FTELL64(pZip->m_pState->m_pFile);
4043 file_ofs += pZip->m_pState->m_file_archive_start_ofs;
4045 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))))
4048 return MZ_FREAD(pBuf, 1, n, pZip->m_pState->m_pFile);
4058 mz_uint64 file_size;
4068 file_size = archive_size;
4094 pZip->m_zip_type = MZ_ZIP_TYPE_FILE;
4096 pZip->m_pIO_opaque = pZip;
4097 pZip->m_pState->m_pFile = pFile;
4098 pZip->m_archive_size = file_size;
4099 pZip->m_pState->m_file_archive_start_ofs = file_start_ofs;
4112 mz_uint64 cur_file_ofs;
4114 if ((!pZip) || (!pFile))
4124 archive_size =
MZ_FTELL64(pFile) - cur_file_ofs;
4133 pZip->m_zip_type = MZ_ZIP_TYPE_CFILE;
4136 pZip->m_pIO_opaque = pZip;
4137 pZip->m_pState->m_pFile = pFile;
4138 pZip->m_archive_size = archive_size;
4139 pZip->m_pState->m_file_archive_start_ofs = cur_file_ofs;
4152static MZ_FORCEINLINE
const mz_uint8 *
mz_zip_get_cdh(mz_zip_archive *pZip, mz_uint file_index)
4154 if ((!pZip) || (!pZip->m_pState) || (file_index >= pZip->m_total_files))
4152static MZ_FORCEINLINE
const mz_uint8 *
mz_zip_get_cdh(mz_zip_archive *pZip, mz_uint file_index) {
…}
4211 mz_uint filename_len, attribute_mapping_id, external_attr;
4230 (void)attribute_mapping_id;
4241static 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)
4244 const mz_uint8 *p = pCentral_dir_header;
4246 if (pFound_zip64_extra_data)
4247 *pFound_zip64_extra_data = MZ_FALSE;
4249 if ((!p) || (!pStat))
4253 pStat->m_file_index = file_index;
4254 pStat->m_central_dir_ofs =
MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index);
4259#ifndef MINIZ_NO_TIME
4271 n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE - 1);
4273 pStat->m_filename[n] =
'\0';
4276 n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE - 1);
4277 pStat->m_comment_size = n;
4279 pStat->m_comment[n] =
'\0';
4288 if (MZ_MAX(MZ_MAX(pStat->m_comp_size, pStat->m_uncomp_size), pStat->m_local_header_ofs) == MZ_UINT32_MAX)
4293 if (extra_size_remaining)
4300 mz_uint32 field_data_size;
4302 if (extra_size_remaining < (
sizeof(mz_uint16) * 2))
4305 field_id = MZ_READ_LE16(pExtra_data);
4306 field_data_size = MZ_READ_LE16(pExtra_data +
sizeof(mz_uint16));
4308 if ((field_data_size +
sizeof(mz_uint16) * 2) > extra_size_remaining)
4313 const mz_uint8 *pField_data = pExtra_data +
sizeof(mz_uint16) * 2;
4314 mz_uint32 field_data_remaining = field_data_size;
4316 if (pFound_zip64_extra_data)
4317 *pFound_zip64_extra_data = MZ_TRUE;
4319 if (pStat->m_uncomp_size == MZ_UINT32_MAX)
4321 if (field_data_remaining <
sizeof(mz_uint64))
4324 pStat->m_uncomp_size = MZ_READ_LE64(pField_data);
4325 pField_data +=
sizeof(mz_uint64);
4326 field_data_remaining -=
sizeof(mz_uint64);
4329 if (pStat->m_comp_size == MZ_UINT32_MAX)
4331 if (field_data_remaining <
sizeof(mz_uint64))
4334 pStat->m_comp_size = MZ_READ_LE64(pField_data);
4335 pField_data +=
sizeof(mz_uint64);
4336 field_data_remaining -=
sizeof(mz_uint64);
4339 if (pStat->m_local_header_ofs == MZ_UINT32_MAX)
4341 if (field_data_remaining <
sizeof(mz_uint64))
4344 pStat->m_local_header_ofs = MZ_READ_LE64(pField_data);
4345 pField_data +=
sizeof(mz_uint64);
4346 field_data_remaining -=
sizeof(mz_uint64);
4352 pExtra_data +=
sizeof(mz_uint16) * 2 + field_data_size;
4353 extra_size_remaining = extra_size_remaining -
sizeof(mz_uint16) * 2 - field_data_size;
4354 }
while (extra_size_remaining);
4241static 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) {
…}
4364 if (flags & MZ_ZIP_FLAG_CASE_SENSITIVE)
4365 return 0 == memcmp(
pA, pB, len);
4366 for (i = 0; i < len; ++i)
4376 mz_uint8 l = 0, r = 0;
4378 pE = pL + MZ_MIN(l_len, r_len);
4386 return (pL == pE) ? (
int)(l_len - r_len) : (l - r);
4391 mz_zip_internal_state *pState = pZip->m_pState;
4392 const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets;
4393 const mz_zip_array *pCentral_dir = &pState->m_central_dir;
4394 mz_uint32 *pIndices = &
MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0);
4395 const mz_uint32
size = pZip->m_total_files;
4396 const mz_uint filename_len = (mz_uint)strlen(pFilename);
4405 mz_int64 l = 0, h = (mz_int64)
size - 1;
4409 mz_int64 m = l + ((h - l) >> 1);
4410 mz_uint32 file_index = pIndices[(mz_uint32)m];
4416 *pIndex = file_index;
4441 size_t name_len, comment_len;
4446 if ((!pZip) || (!pZip->m_pState) || (!pName))
4450 if (((pZip->m_pState->m_init_flags & MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY) == 0) &&
4451 (pZip->m_zip_mode == MZ_ZIP_MODE_READING) &&
4452 ((flags & (MZ_ZIP_FLAG_IGNORE_PATH | MZ_ZIP_FLAG_CASE_SENSITIVE)) == 0) && (!pComment) && (pZip->m_pState->m_sorted_central_dir_offsets.m_size))
4458 name_len = strlen(pName);
4459 if (name_len > MZ_UINT16_MAX)
4462 comment_len = pComment ? strlen(pComment) : 0;
4463 if (comment_len > MZ_UINT16_MAX)
4466 for (file_index = 0; file_index < pZip->m_total_files; file_index++)
4471 if (filename_len < name_len)
4476 const char *pFile_comment = pFilename + filename_len + file_extra_len;
4477 if ((file_comment_len != comment_len) || (!
mz_zip_string_equal(pComment, pFile_comment, file_comment_len, flags)))
4480 if ((flags & MZ_ZIP_FLAG_IGNORE_PATH) && (filename_len))
4482 int ofs = filename_len - 1;
4485 if ((pFilename[ofs] ==
'/') || (pFilename[ofs] ==
'\\') || (pFilename[ofs] ==
':'))
4487 }
while (--ofs >= 0);
4490 filename_len -= ofs;
4492 if ((filename_len == name_len) && (
mz_zip_string_equal(pName, pFilename, filename_len, flags)))
4495 *pIndex = file_index;
4504mz_bool
mz_zip_reader_extract_to_mem_no_alloc1(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,
const mz_zip_archive_file_stat *st)
4506 int status = TINFL_STATUS_DONE;
4507 mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail;
4508 mz_zip_archive_file_stat file_stat;
4511 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
4512 tinfl_decompressor inflator;
4514 if ((!pZip) || (!pZip->m_pState) || ((buf_size) && (!pBuf)) || ((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead))
4524 if ((file_stat.m_is_directory) || (!file_stat.m_comp_size))
4532 if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method !=
MZ_DEFLATED))
4536 needed_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? file_stat.m_comp_size : file_stat.m_uncomp_size;
4537 if (buf_size < needed_size)
4541 cur_file_ofs = file_stat.m_local_header_ofs;
4549 if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size)
4552 if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method))
4555 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, (
size_t)needed_size) != needed_size)
4558#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4559 if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) == 0)
4561 if (
mz_crc32(
MZ_CRC32_INIT, (
const mz_uint8 *)pBuf, (
size_t)file_stat.m_uncomp_size) != file_stat.m_crc32)
4570 tinfl_init(&inflator);
4572 if (pZip->m_pState->m_pMem)
4575 pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs;
4576 read_buf_size = read_buf_avail = file_stat.m_comp_size;
4579 else if (pUser_read_buf)
4582 if (!user_read_buf_size)
4584 pRead_buf = (mz_uint8 *)pUser_read_buf;
4585 read_buf_size = user_read_buf_size;
4587 comp_remaining = file_stat.m_comp_size;
4592 read_buf_size = MZ_MIN(file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
4593 if (((
sizeof(
size_t) ==
sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF))
4596 if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (
size_t)read_buf_size)))
4600 comp_remaining = file_stat.m_comp_size;
4606 size_t in_buf_size, out_buf_size = (size_t)(file_stat.m_uncomp_size - out_buf_ofs);
4607 if ((!read_buf_avail) && (!pZip->m_pState->m_pMem))
4609 read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
4610 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
4612 status = TINFL_STATUS_FAILED;
4616 cur_file_ofs += read_buf_avail;
4617 comp_remaining -= read_buf_avail;
4620 in_buf_size = (size_t)read_buf_avail;
4621 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));
4622 read_buf_avail -= in_buf_size;
4623 read_buf_ofs += in_buf_size;
4624 out_buf_ofs += out_buf_size;
4625 }
while (status == TINFL_STATUS_NEEDS_MORE_INPUT);
4627 if (status == TINFL_STATUS_DONE)
4630 if (out_buf_ofs != file_stat.m_uncomp_size)
4633 status = TINFL_STATUS_FAILED;
4635#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4636 else if (
mz_crc32(
MZ_CRC32_INIT, (
const mz_uint8 *)pBuf, (
size_t)file_stat.m_uncomp_size) != file_stat.m_crc32)
4639 status = TINFL_STATUS_FAILED;
4644 if ((!pZip->m_pState->m_pMem) && (!pUser_read_buf))
4645 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
4647 return status == TINFL_STATUS_DONE;
4504mz_bool
mz_zip_reader_extract_to_mem_no_alloc1(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,
const mz_zip_archive_file_stat *st) {
…}
4657 mz_uint32 file_index;
4675 mz_zip_archive_file_stat file_stat;
4676 mz_uint64 alloc_size;
4685 alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? file_stat.m_comp_size : file_stat.m_uncomp_size;
4686 if (((
sizeof(
size_t) ==
sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF))
4692 if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (
size_t)alloc_size)))
4700 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
4705 *pSize = (size_t)alloc_size;
4711 mz_uint32 file_index;
4723 int status = TINFL_STATUS_DONE;
4724#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4727 mz_uint64 read_buf_size, read_buf_ofs = 0, read_buf_avail, comp_remaining, out_buf_ofs = 0, cur_file_ofs;
4728 mz_zip_archive_file_stat file_stat;
4729 void *pRead_buf = NULL;
4730 void *pWrite_buf = NULL;
4732 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
4734 if ((!pZip) || (!pZip->m_pState) || (!pCallback) || (!pZip->m_pRead))
4741 if ((file_stat.m_is_directory) || (!file_stat.m_comp_size))
4749 if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method !=
MZ_DEFLATED))
4753 cur_file_ofs = file_stat.m_local_header_ofs;
4761 if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size)
4765 if (pZip->m_pState->m_pMem)
4767 pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs;
4768 read_buf_size = read_buf_avail = file_stat.m_comp_size;
4773 read_buf_size = MZ_MIN(file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
4774 if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (
size_t)read_buf_size)))
4778 comp_remaining = file_stat.m_comp_size;
4781 if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method))
4784 if (pZip->m_pState->m_pMem)
4786 if (((
sizeof(
size_t) ==
sizeof(mz_uint32))) && (file_stat.m_comp_size > MZ_UINT32_MAX))
4789 if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (
size_t)file_stat.m_comp_size) != file_stat.m_comp_size)
4792 status = TINFL_STATUS_FAILED;
4794 else if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
4796#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4797 file_crc32 = (mz_uint32)
mz_crc32(file_crc32, (
const mz_uint8 *)pRead_buf, (
size_t)file_stat.m_comp_size);
4801 cur_file_ofs += file_stat.m_comp_size;
4802 out_buf_ofs += file_stat.m_comp_size;
4807 while (comp_remaining)
4809 read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
4810 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
4813 status = TINFL_STATUS_FAILED;
4817#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4818 if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
4820 file_crc32 = (mz_uint32)
mz_crc32(file_crc32, (
const mz_uint8 *)pRead_buf, (
size_t)read_buf_avail);
4824 if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
4827 status = TINFL_STATUS_FAILED;
4831 cur_file_ofs += read_buf_avail;
4832 out_buf_ofs += read_buf_avail;
4833 comp_remaining -= read_buf_avail;
4839 tinfl_decompressor inflator;
4840 tinfl_init(&inflator);
4842 if (NULL == (pWrite_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, TINFL_LZ_DICT_SIZE)))
4845 status = TINFL_STATUS_FAILED;
4851 mz_uint8 *pWrite_buf_cur = (mz_uint8 *)pWrite_buf + (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
4852 size_t in_buf_size, out_buf_size = TINFL_LZ_DICT_SIZE - (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
4853 if ((!read_buf_avail) && (!pZip->m_pState->m_pMem))
4855 read_buf_avail = MZ_MIN(read_buf_size, comp_remaining);
4856 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (
size_t)read_buf_avail) != read_buf_avail)
4859 status = TINFL_STATUS_FAILED;
4862 cur_file_ofs += read_buf_avail;
4863 comp_remaining -= read_buf_avail;
4867 in_buf_size = (size_t)read_buf_avail;
4868 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);
4869 read_buf_avail -= in_buf_size;
4870 read_buf_ofs += in_buf_size;
4874 if (pCallback(pOpaque, out_buf_ofs, pWrite_buf_cur, out_buf_size) != out_buf_size)
4877 status = TINFL_STATUS_FAILED;
4881#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4882 file_crc32 = (mz_uint32)
mz_crc32(file_crc32, pWrite_buf_cur, out_buf_size);
4884 if ((out_buf_ofs += out_buf_size) > file_stat.m_uncomp_size)
4887 status = TINFL_STATUS_FAILED;
4891 }
while ((status == TINFL_STATUS_NEEDS_MORE_INPUT) || (status == TINFL_STATUS_HAS_MORE_OUTPUT));
4895 if ((status == TINFL_STATUS_DONE) && (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)))
4898 if (out_buf_ofs != file_stat.m_uncomp_size)
4901 status = TINFL_STATUS_FAILED;
4903#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4904 else if (file_crc32 != file_stat.m_crc32)
4907 status = TINFL_STATUS_FAILED;
4912 if (!pZip->m_pState->m_pMem)
4913 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
4916 pZip->m_pFree(pZip->m_pAlloc_opaque, pWrite_buf);
4918 return status == TINFL_STATUS_DONE;
4923 mz_uint32 file_index;
4932 mz_zip_reader_extract_iter_state *pState;
4934 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
4937 if ((!pZip) || (!pZip->m_pState))
4941 pState = (mz_zip_reader_extract_iter_state*)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1,
sizeof(mz_zip_reader_extract_iter_state));
4951 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
4959 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
4964 if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (pState->file_stat.m_method != 0) && (pState->file_stat.m_method !=
MZ_DEFLATED))
4967 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
4972 pState->pZip = pZip;
4973 pState->flags = flags;
4976 pState->status = TINFL_STATUS_DONE;
4977#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
4980 pState->read_buf_ofs = 0;
4981 pState->out_buf_ofs = 0;
4982 pState->pRead_buf = NULL;
4983 pState->pWrite_buf = NULL;
4984 pState->out_blk_remain = 0;
4987 pState->cur_file_ofs = pState->file_stat.m_local_header_ofs;
4991 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
4998 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
5003 if ((pState->cur_file_ofs + pState->file_stat.m_comp_size) > pZip->m_archive_size)
5006 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
5011 if (pZip->m_pState->m_pMem)
5013 pState->pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + pState->cur_file_ofs;
5014 pState->read_buf_size = pState->read_buf_avail = pState->file_stat.m_comp_size;
5015 pState->comp_remaining = pState->file_stat.m_comp_size;
5019 if (!((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method)))
5022 pState->read_buf_size = MZ_MIN(pState->file_stat.m_comp_size, (mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE);
5023 if (NULL == (pState->pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (
size_t)pState->read_buf_size)))
5026 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
5033 pState->read_buf_size = 0;
5035 pState->read_buf_avail = 0;
5036 pState->comp_remaining = pState->file_stat.m_comp_size;
5039 if (!((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method)))
5042 tinfl_init( &pState->inflator );
5045 if (NULL == (pState->pWrite_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, TINFL_LZ_DICT_SIZE)))
5048 if (pState->pRead_buf)
5049 pZip->m_pFree(pZip->m_pAlloc_opaque, pState->pRead_buf);
5050 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
5060 mz_uint32 file_index;
5072 size_t copied_to_caller = 0;
5075 if ((!pState) || (!pState->pZip) || (!pState->pZip->m_pState) || (!pvBuf))
5078 if ((pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!pState->file_stat.m_method))
5081 copied_to_caller = (size_t)MZ_MIN( buf_size, pState->comp_remaining );
5084 if (pState->pZip->m_pState->m_pMem)
5087 memcpy( pvBuf, pState->pRead_buf, copied_to_caller );
5088 pState->pRead_buf = ((mz_uint8*)pState->pRead_buf) + copied_to_caller;
5093 if (pState->pZip->m_pRead(pState->pZip->m_pIO_opaque, pState->cur_file_ofs, pvBuf, copied_to_caller) != copied_to_caller)
5097 pState->status = TINFL_STATUS_FAILED;
5098 copied_to_caller = 0;
5102#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
5104 if (!(pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
5105 pState->file_crc32 = (mz_uint32)
mz_crc32(pState->file_crc32, (
const mz_uint8 *)pvBuf, copied_to_caller);
5109 pState->cur_file_ofs += copied_to_caller;
5110 pState->out_buf_ofs += copied_to_caller;
5111 pState->comp_remaining -= copied_to_caller;
5118 mz_uint8 *pWrite_buf_cur = (mz_uint8 *)pState->pWrite_buf + (pState->out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
5121 size_t in_buf_size, out_buf_size = TINFL_LZ_DICT_SIZE - (pState->out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1));
5123 if (!pState->out_blk_remain)
5126 if ((!pState->read_buf_avail) && (!pState->pZip->m_pState->m_pMem))
5129 pState->read_buf_avail = MZ_MIN(pState->read_buf_size, pState->comp_remaining);
5130 if (pState->pZip->m_pRead(pState->pZip->m_pIO_opaque, pState->cur_file_ofs, pState->pRead_buf, (
size_t)pState->read_buf_avail) != pState->read_buf_avail)
5133 pState->status = TINFL_STATUS_FAILED;
5138 pState->cur_file_ofs += pState->read_buf_avail;
5139 pState->comp_remaining -= pState->read_buf_avail;
5140 pState->read_buf_ofs = 0;
5144 in_buf_size = (size_t)pState->read_buf_avail;
5145 pState->status =
tinfl_decompress(&pState->inflator, (
const mz_uint8 *)pState->pRead_buf + pState->read_buf_ofs, &in_buf_size, (mz_uint8 *)pState->pWrite_buf, pWrite_buf_cur, &out_buf_size, pState->comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0);
5146 pState->read_buf_avail -= in_buf_size;
5147 pState->read_buf_ofs += in_buf_size;
5150 pState->out_blk_remain = out_buf_size;
5153 if (pState->out_blk_remain)
5156 size_t to_copy = MZ_MIN( (buf_size - copied_to_caller), pState->out_blk_remain );
5159 memcpy( (mz_uint8*)pvBuf + copied_to_caller, pWrite_buf_cur, to_copy );
5161#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
5163 pState->file_crc32 = (mz_uint32)
mz_crc32(pState->file_crc32, pWrite_buf_cur, to_copy);
5167 pState->out_blk_remain -= to_copy;
5170 if ((pState->out_buf_ofs += to_copy) > pState->file_stat.m_uncomp_size)
5173 pState->status = TINFL_STATUS_FAILED;
5178 copied_to_caller += to_copy;
5180 }
while ( (copied_to_caller < buf_size) && ((pState->status == TINFL_STATUS_NEEDS_MORE_INPUT) || (pState->status == TINFL_STATUS_HAS_MORE_OUTPUT)) );
5184 return copied_to_caller;
5192 if ((!pState) || (!pState->pZip) || (!pState->pZip->m_pState))
5196 if ((pState->status == TINFL_STATUS_DONE) && (!(pState->flags & MZ_ZIP_FLAG_COMPRESSED_DATA)))
5199 if (pState->out_buf_ofs != pState->file_stat.m_uncomp_size)
5202 pState->status = TINFL_STATUS_FAILED;
5204#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
5205 else if (pState->file_crc32 != pState->file_stat.m_crc32)
5208 pState->status = TINFL_STATUS_FAILED;
5214 if (!pState->pZip->m_pState->m_pMem)
5215 pState->pZip->m_pFree(pState->pZip->m_pAlloc_opaque, pState->pRead_buf);
5216 if (pState->pWrite_buf)
5217 pState->pZip->m_pFree(pState->pZip->m_pAlloc_opaque, pState->pWrite_buf);
5220 status = pState->status;
5223 pState->pZip->m_pFree(pState->pZip->m_pAlloc_opaque, pState);
5225 return status == TINFL_STATUS_DONE;
5228#ifndef MINIZ_NO_STDIO
5233 return MZ_FWRITE(pBuf, 1, n, (MZ_FILE *)pOpaque);
5239 mz_zip_archive_file_stat file_stat;
5245 if ((file_stat.m_is_directory) || (!file_stat.m_is_supported))
5248 pFile =
MZ_FOPEN(pDst_filename,
"wb");
5262#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_STDIO)
5272 mz_uint32 file_index;
5281 mz_zip_archive_file_stat file_stat;
5286 if ((file_stat.m_is_directory) || (!file_stat.m_is_supported))
5294 mz_uint32 file_index;
5304 mz_uint32 *p = (mz_uint32 *)pOpaque;
5306 *p = (mz_uint32)
mz_crc32(*p, (
const mz_uint8 *)pBuf, n);
5312 mz_zip_archive_file_stat file_stat;
5313 mz_zip_internal_state *pState;
5314 const mz_uint8 *pCentral_dir_header;
5315 mz_bool found_zip64_ext_data_in_cdir = MZ_FALSE;
5316 mz_bool found_zip64_ext_data_in_ldir = MZ_FALSE;
5318 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
5319 mz_uint64 local_header_ofs = 0;
5320 mz_uint32 local_header_filename_len, local_header_extra_len, local_header_crc32;
5321 mz_uint64 local_header_comp_size, local_header_uncomp_size;
5323 mz_bool has_data_descriptor;
5324 mz_uint32 local_header_bit_flags;
5329 if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (!pZip->m_pRead))
5332 if (file_index > pZip->m_total_files)
5335 pState = pZip->m_pState;
5343 if ((file_stat.m_is_directory) || (!file_stat.m_uncomp_size))
5347 if (file_stat.m_is_encrypted)
5351 if ((file_stat.m_method != 0) && (file_stat.m_method !=
MZ_DEFLATED))
5354 if (!file_stat.m_is_supported)
5358 local_header_ofs = file_stat.m_local_header_ofs;
5371 has_data_descriptor = (local_header_bit_flags & 8) != 0;
5373 if (local_header_filename_len != strlen(file_stat.m_filename))
5376 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)
5379 if (!
mz_zip_array_resize(pZip, &file_data_array, MZ_MAX(local_header_filename_len, local_header_extra_len), MZ_FALSE))
5382 goto handle_failure;
5385 if (local_header_filename_len)
5387 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)
5390 goto handle_failure;
5394 if (memcmp(file_stat.m_filename, file_data_array.
m_p, local_header_filename_len) != 0)
5397 goto handle_failure;
5401 if ((local_header_extra_len) && ((local_header_comp_size == MZ_UINT32_MAX) || (local_header_uncomp_size == MZ_UINT32_MAX)))
5403 mz_uint32 extra_size_remaining = local_header_extra_len;
5404 const mz_uint8 *pExtra_data = (
const mz_uint8 *)file_data_array.
m_p;
5406 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)
5409 goto handle_failure;
5414 mz_uint32 field_id, field_data_size, field_total_size;
5416 if (extra_size_remaining < (
sizeof(mz_uint16) * 2))
5419 goto handle_failure;
5422 field_id = MZ_READ_LE16(pExtra_data);
5423 field_data_size = MZ_READ_LE16(pExtra_data +
sizeof(mz_uint16));
5424 field_total_size = field_data_size +
sizeof(mz_uint16) * 2;
5426 if (field_total_size > extra_size_remaining)
5429 goto handle_failure;
5434 const mz_uint8 *pSrc_field_data = pExtra_data +
sizeof(mz_uint32);
5436 if (field_data_size <
sizeof(mz_uint64) * 2)
5439 goto handle_failure;
5442 local_header_uncomp_size = MZ_READ_LE64(pSrc_field_data);
5443 local_header_comp_size = MZ_READ_LE64(pSrc_field_data +
sizeof(mz_uint64));
5445 found_zip64_ext_data_in_ldir = MZ_TRUE;
5449 pExtra_data += field_total_size;
5450 extra_size_remaining -= field_total_size;
5451 }
while (extra_size_remaining);
5456 if ((has_data_descriptor) && (!local_header_comp_size) && (!local_header_crc32))
5458 mz_uint8 descriptor_buf[32];
5460 const mz_uint8 *pSrc;
5461 mz_uint32 file_crc32;
5462 mz_uint64 comp_size = 0, uncomp_size = 0;
5464 mz_uint32 num_descriptor_uint32s = ((pState->m_zip64) || (found_zip64_ext_data_in_ldir)) ? 6 : 4;
5466 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))
5469 goto handle_failure;
5473 pSrc = has_id ? (descriptor_buf +
sizeof(mz_uint32)) : descriptor_buf;
5475 file_crc32 = MZ_READ_LE32(pSrc);
5477 if ((pState->m_zip64) || (found_zip64_ext_data_in_ldir))
5479 comp_size = MZ_READ_LE64(pSrc +
sizeof(mz_uint32));
5480 uncomp_size = MZ_READ_LE64(pSrc +
sizeof(mz_uint32) +
sizeof(mz_uint64));
5484 comp_size = MZ_READ_LE32(pSrc +
sizeof(mz_uint32));
5485 uncomp_size = MZ_READ_LE32(pSrc +
sizeof(mz_uint32) +
sizeof(mz_uint32));
5488 if ((file_crc32 != file_stat.m_crc32) || (comp_size != file_stat.m_comp_size) || (uncomp_size != file_stat.m_uncomp_size))
5491 goto handle_failure;
5496 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))
5499 goto handle_failure;
5505 if ((flags & MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY) == 0)
5511 if (uncomp_crc32 != file_stat.m_crc32)
5527 mz_zip_internal_state *pState;
5530 if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (!pZip->m_pRead))
5533 pState = pZip->m_pState;
5536 if (!pState->m_zip64)
5538 if (pZip->m_total_files > MZ_UINT16_MAX)
5541 if (pZip->m_archive_size > MZ_UINT32_MAX)
5546 if (pState->m_central_dir.m_size >= MZ_UINT32_MAX)
5550 for (i = 0; i < pZip->m_total_files; i++)
5552 if (MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG & flags)
5554 mz_uint32 found_index;
5555 mz_zip_archive_file_stat stat;
5564 if (found_index != i)
5577 mz_bool success = MZ_TRUE;
5579 mz_zip_error actual_err = MZ_ZIP_NO_ERROR;
5581 if ((!pMem) || (!
size))
5584 *pErr = MZ_ZIP_INVALID_PARAMETER;
5593 *pErr = zip.m_last_error;
5599 actual_err = zip.m_last_error;
5606 actual_err = zip.m_last_error;
5616#ifndef MINIZ_NO_STDIO
5619 mz_bool success = MZ_TRUE;
5621 mz_zip_error actual_err = MZ_ZIP_NO_ERROR;
5626 *pErr = MZ_ZIP_INVALID_PARAMETER;
5635 *pErr = zip.m_last_error;
5641 actual_err = zip.m_last_error;
5648 actual_err = zip.m_last_error;
5661#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
5666 p[1] = (mz_uint8)(v >> 8);
5671 p[1] = (mz_uint8)(v >> 8);
5672 p[2] = (mz_uint8)(v >> 16);
5673 p[3] = (mz_uint8)(v >> 24);
5681#define MZ_WRITE_LE16(p, v) mz_write_le16((mz_uint8 *)(p), (mz_uint16)(v))
5682#define MZ_WRITE_LE32(p, v) mz_write_le32((mz_uint8 *)(p), (mz_uint32)(v))
5683#define MZ_WRITE_LE64(p, v) mz_write_le64((mz_uint8 *)(p), (mz_uint64)(v))
5687 mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
5688 mz_zip_internal_state *pState = pZip->m_pState;
5689 mz_uint64 new_size = MZ_MAX(file_ofs + n, pState->m_mem_size);
5695 if ((
sizeof(
size_t) ==
sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF))
5701 if (new_size > pState->m_mem_capacity)
5704 size_t new_capacity = MZ_MAX(64, pState->m_mem_capacity);
5706 while (new_capacity < new_size)
5709 if (NULL == (pNew_block = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pState->m_pMem, 1, new_capacity)))
5715 pState->m_pMem = pNew_block;
5716 pState->m_mem_capacity = new_capacity;
5718 memcpy((mz_uint8 *)pState->m_pMem + file_ofs, pBuf, n);
5719 pState->m_mem_size = (size_t)new_size;
5725 mz_zip_internal_state *pState;
5726 mz_bool status = MZ_TRUE;
5728 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)))
5735 pState = pZip->m_pState;
5736 pZip->m_pState = NULL;
5741#ifndef MINIZ_NO_STDIO
5742 if (pState->m_pFile)
5744 if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE)
5754 pState->m_pFile = NULL;
5760 pZip->m_pFree(pZip->m_pAlloc_opaque, pState->m_pMem);
5761 pState->m_pMem = NULL;
5764 pZip->m_pFree(pZip->m_pAlloc_opaque, pState);
5765 pZip->m_zip_mode = MZ_ZIP_MODE_INVALID;
5771 mz_bool zip64 = (flags & MZ_ZIP_FLAG_WRITE_ZIP64) != 0;
5773 if ((!pZip) || (pZip->m_pState) || (!pZip->m_pWrite) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID))
5776 if (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING)
5782 if (pZip->m_file_offset_alignment)
5785 if (pZip->m_file_offset_alignment & (pZip->m_file_offset_alignment - 1))
5789 if (!pZip->m_pAlloc)
5793 if (!pZip->m_pRealloc)
5796 pZip->m_archive_size = existing_size;
5797 pZip->m_central_directory_file_ofs = 0;
5798 pZip->m_total_files = 0;
5800 if (NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1,
sizeof(mz_zip_internal_state))))
5803 memset(pZip->m_pState, 0,
sizeof(mz_zip_internal_state));
5809 pZip->m_pState->m_zip64 = zip64;
5810 pZip->m_pState->m_zip64_has_extended_info_fields = zip64;
5812 pZip->m_zip_type = MZ_ZIP_TYPE_USER;
5813 pZip->m_zip_mode = MZ_ZIP_MODE_WRITING;
5826 pZip->m_pNeeds_keepalive = NULL;
5828 if (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING)
5831 pZip->m_pIO_opaque = pZip;
5836 pZip->m_zip_type = MZ_ZIP_TYPE_HEAP;
5838 if (0 != (initial_allocation_size = MZ_MAX(initial_allocation_size, size_to_reserve_at_beginning)))
5840 if (NULL == (pZip->m_pState->m_pMem = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, initial_allocation_size)))
5845 pZip->m_pState->m_mem_capacity = initial_allocation_size;
5856#ifndef MINIZ_NO_STDIO
5859 mz_zip_archive *pZip = (mz_zip_archive *)pOpaque;
5860 mz_int64 cur_ofs =
MZ_FTELL64(pZip->m_pState->m_pFile);
5862 file_ofs += pZip->m_pState->m_file_archive_start_ofs;
5864 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))))
5870 return MZ_FWRITE(pBuf, 1, n, pZip->m_pState->m_pFile);
5883 pZip->m_pNeeds_keepalive = NULL;
5885 if (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING)
5888 pZip->m_pIO_opaque = pZip;
5893 if (NULL == (pFile =
MZ_FOPEN(pFilename, (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING) ?
"w+b" :
"wb")))
5899 pZip->m_pState->m_pFile = pFile;
5900 pZip->m_zip_type = MZ_ZIP_TYPE_FILE;
5902 if (size_to_reserve_at_beginning)
5904 mz_uint64 cur_ofs = 0;
5911 size_t n = (size_t)MZ_MIN(
sizeof(
buf), size_to_reserve_at_beginning);
5912 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_ofs,
buf, n) != n)
5918 size_to_reserve_at_beginning -= n;
5919 }
while (size_to_reserve_at_beginning);
5928 pZip->m_pNeeds_keepalive = NULL;
5930 if (flags & MZ_ZIP_FLAG_WRITE_ALLOW_READING)
5933 pZip->m_pIO_opaque = pZip;
5938 pZip->m_pState->m_pFile = pFile;
5939 pZip->m_pState->m_file_archive_start_ofs =
MZ_FTELL64(pZip->m_pState->m_pFile);
5940 pZip->m_zip_type = MZ_ZIP_TYPE_CFILE;
5948 mz_zip_internal_state *pState;
5950 if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING))
5953 if (flags & MZ_ZIP_FLAG_WRITE_ZIP64)
5956 if (!pZip->m_pState->m_zip64)
5961 if (pZip->m_pState->m_zip64)
5963 if (pZip->m_total_files == MZ_UINT32_MAX)
5968 if (pZip->m_total_files == MZ_UINT16_MAX)
5975 pState = pZip->m_pState;
5977 if (pState->m_pFile)
5979#ifdef MINIZ_NO_STDIO
5983 if (pZip->m_pIO_opaque != pZip)
5986 if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE)
5992 if (NULL == (pState->m_pFile =
MZ_FREOPEN(pFilename,
"r+b", pState->m_pFile)))
6001 pZip->m_pNeeds_keepalive = NULL;
6004 else if (pState->m_pMem)
6007 if (pZip->m_pIO_opaque != pZip)
6010 pState->m_mem_capacity = pState->m_mem_size;
6012 pZip->m_pNeeds_keepalive = NULL;
6015 else if (!pZip->m_pWrite)
6020 pZip->m_archive_size = pZip->m_central_directory_file_ofs;
6021 pZip->m_central_directory_file_ofs = 0;
6028 pZip->m_zip_mode = MZ_ZIP_MODE_WRITING;
6039mz_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)
6039mz_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) {
…}
6062#define MZ_ZIP64_MAX_LOCAL_EXTRA_FIELD_SIZE (sizeof(mz_uint16) * 2 + sizeof(mz_uint64) * 2)
6063#define MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE (sizeof(mz_uint16) * 2 + sizeof(mz_uint64) * 3)
6066 mz_uint8 *pDst = pBuf;
6067 mz_uint32 field_size = 0;
6071 pDst +=
sizeof(mz_uint16) * 2;
6076 pDst +=
sizeof(mz_uint64);
6077 field_size +=
sizeof(mz_uint64);
6083 pDst +=
sizeof(mz_uint64);
6084 field_size +=
sizeof(mz_uint64);
6087 if (pLocal_header_ofs)
6090 pDst +=
sizeof(mz_uint64);
6091 field_size +=
sizeof(mz_uint64);
6096 return (mz_uint32)(pDst - pBuf);
6099static 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)
6099static 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) {
…}
6118 mz_uint16 filename_size, mz_uint16 extra_size, mz_uint16 comment_size,
6119 mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32,
6120 mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date,
6121 mz_uint64 local_header_ofs, mz_uint32 ext_attributes)
6143 const void *pExtra, mz_uint16 extra_size,
const void *pComment, mz_uint16 comment_size,
6144 mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32,
6145 mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date,
6146 mz_uint64 local_header_ofs, mz_uint32 ext_attributes,
6147 const char *user_extra_data, mz_uint user_extra_data_len)
6149 mz_zip_internal_state *pState = pZip->m_pState;
6150 mz_uint32 central_dir_ofs = (mz_uint32)pState->m_central_dir.m_size;
6151 size_t orig_central_dir_size = pState->m_central_dir.m_size;
6154 if (!pZip->m_pState->m_zip64)
6156 if (local_header_ofs > 0xFFFFFFFF)
6161 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)
6164 if (!
mz_zip_writer_create_central_dir_header(pZip, central_dir_header, filename_size, (mz_uint16)(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))
6185 if (*pArchive_name ==
'/')
6196 if (!pZip->m_file_offset_alignment)
6198 n = (mz_uint32)(pZip->m_archive_size & (pZip->m_file_offset_alignment - 1));
6199 return (mz_uint)((pZip->m_file_offset_alignment - n) & (pZip->m_file_offset_alignment - 1));
6205 memset(
buf, 0, MZ_MIN(
sizeof(
buf), n));
6208 mz_uint32 s = MZ_MIN(
sizeof(
buf), n);
6209 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_file_ofs,
buf, s) != s)
6218mz_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,
6219 mz_uint64 uncomp_size, mz_uint32 uncomp_crc32)
6221 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);
6218mz_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, {
…}
6224mz_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,
6225 mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified,
6226 const char *user_extra_data, mz_uint user_extra_data_len,
const char *user_extra_data_central, mz_uint user_extra_data_central_len)
6228 mz_uint16 method = 0, dos_time = 0, dos_date = 0;
6229 mz_uint level, ext_attributes = 0, num_alignment_padding_bytes;
6230 mz_uint64 local_dir_header_ofs = pZip->m_archive_size, cur_archive_file_ofs = pZip->m_archive_size, comp_size = 0;
6231 size_t archive_name_size;
6233 tdefl_compressor *pComp = NULL;
6234 mz_bool store_data_uncompressed;
6235 mz_zip_internal_state *pState;
6236 mz_uint8 *pExtra_data = NULL;
6237 mz_uint32 extra_size = 0;
6239 mz_uint16 bit_flags = 0;
6241 if ((
int)level_and_flags < 0)
6244 if (uncomp_size || (buf_size && !(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)))
6247 if (!(level_and_flags & MZ_ZIP_FLAG_ASCII_FILENAME))
6250 level = level_and_flags & 0xF;
6251 store_data_uncompressed = ((!level) || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA));
6253 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))
6256 pState = pZip->m_pState;
6258 if (pState->m_zip64)
6260 if (pZip->m_total_files == MZ_UINT32_MAX)
6265 if (pZip->m_total_files == MZ_UINT16_MAX)
6267 pState->m_zip64 = MZ_TRUE;
6270 if (((mz_uint64)buf_size > 0xFFFFFFFF) || (uncomp_size > 0xFFFFFFFF))
6272 pState->m_zip64 = MZ_TRUE;
6277 if ((!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (uncomp_size))
6283#ifndef MINIZ_NO_TIME
6284 if (last_modified != NULL)
6296 if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
6299 uncomp_size = buf_size;
6300 if (uncomp_size <= 3)
6303 store_data_uncompressed = MZ_TRUE;
6307 archive_name_size = strlen(pArchive_name);
6308 if (archive_name_size > MZ_UINT16_MAX)
6317 if (!pState->m_zip64)
6325 pState->m_zip64 = MZ_TRUE;
6330 if ((archive_name_size) && (pArchive_name[archive_name_size - 1] ==
'/'))
6336 if ((buf_size) || (uncomp_size))
6344 if ((!store_data_uncompressed) && (buf_size))
6346 if (NULL == (pComp = (tdefl_compressor *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1,
sizeof(tdefl_compressor))))
6352 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
6356 local_dir_header_ofs += num_alignment_padding_bytes;
6357 if (pZip->m_file_offset_alignment)
6359 MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0);
6361 cur_archive_file_ofs += num_alignment_padding_bytes;
6363 MZ_CLEAR_ARR(local_dir_header);
6365 if (!store_data_uncompressed || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
6370 if (pState->m_zip64)
6372 if (uncomp_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX)
6374 pExtra_data = extra_data;
6376 (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
6379 if (!
mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, (mz_uint16)(extra_size + user_extra_data_len), 0, 0, 0, method, bit_flags, dos_time, dos_date))
6382 if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header,
sizeof(local_dir_header)) !=
sizeof(local_dir_header))
6385 cur_archive_file_ofs +=
sizeof(local_dir_header);
6387 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
6389 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
6392 cur_archive_file_ofs += archive_name_size;
6394 if (pExtra_data != NULL)
6396 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, extra_data, extra_size) != extra_size)
6399 cur_archive_file_ofs += extra_size;
6404 if ((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX))
6406 if (!
mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, (mz_uint16)user_extra_data_len, 0, 0, 0, method, bit_flags, dos_time, dos_date))
6409 if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header,
sizeof(local_dir_header)) !=
sizeof(local_dir_header))
6412 cur_archive_file_ofs +=
sizeof(local_dir_header);
6414 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
6416 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
6419 cur_archive_file_ofs += archive_name_size;
6422 if (user_extra_data_len > 0)
6424 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, user_extra_data, user_extra_data_len) != user_extra_data_len)
6427 cur_archive_file_ofs += user_extra_data_len;
6430 if (store_data_uncompressed)
6432 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pBuf, buf_size) != buf_size)
6434 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
6438 cur_archive_file_ofs += buf_size;
6439 comp_size = buf_size;
6452 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
6460 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
6472 if (pExtra_data == NULL)
6474 if (comp_size > MZ_UINT32_MAX)
6487 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_footer, local_dir_footer_size) != local_dir_footer_size)
6490 cur_archive_file_ofs += local_dir_footer_size;
6493 if (pExtra_data != NULL)
6496 (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
6500 comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes,
6501 user_extra_data_central, user_extra_data_central_len))
6504 pZip->m_total_files++;
6505 pZip->m_archive_size = cur_archive_file_ofs;
6224mz_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, {
…}
6510mz_bool
mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip,
const char *pArchive_name, mz_file_read_func read_callback,
void* callback_opaque, mz_uint64 max_size,
const MZ_TIME_T *pFile_time,
const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
6511 const char *user_extra_data, mz_uint user_extra_data_len,
const char *user_extra_data_central, mz_uint user_extra_data_central_len)
6513 mz_uint16 gen_flags;
6514 mz_uint uncomp_crc32 =
MZ_CRC32_INIT, level, num_alignment_padding_bytes;
6515 mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0;
6516 mz_uint64 local_dir_header_ofs, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = 0, comp_size = 0;
6517 size_t archive_name_size;
6519 mz_uint8 *pExtra_data = NULL;
6520 mz_uint32 extra_size = 0;
6522 mz_zip_internal_state *pState;
6523 mz_uint64 file_ofs = 0, cur_archive_header_file_ofs;
6525 if ((
int)level_and_flags < 0)
6527 level = level_and_flags & 0xF;
6531 if (!(level_and_flags & MZ_ZIP_FLAG_ASCII_FILENAME))
6535 if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level >
MZ_UBER_COMPRESSION))
6538 pState = pZip->m_pState;
6540 if ((!pState->m_zip64) && (max_size > MZ_UINT32_MAX))
6544 pState->m_zip64 = MZ_TRUE;
6548 if (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)
6554 if (pState->m_zip64)
6556 if (pZip->m_total_files == MZ_UINT32_MAX)
6561 if (pZip->m_total_files == MZ_UINT16_MAX)
6563 pState->m_zip64 = MZ_TRUE;
6568 archive_name_size = strlen(pArchive_name);
6569 if (archive_name_size > MZ_UINT16_MAX)
6578 if (!pState->m_zip64)
6585 pState->m_zip64 = MZ_TRUE;
6590#ifndef MINIZ_NO_TIME
6605 cur_archive_file_ofs += num_alignment_padding_bytes;
6606 local_dir_header_ofs = cur_archive_file_ofs;
6608 if (pZip->m_file_offset_alignment)
6610 MZ_ASSERT((cur_archive_file_ofs & (pZip->m_file_offset_alignment - 1)) == 0);
6613 if (max_size && level)
6618 MZ_CLEAR_ARR(local_dir_header);
6619 if (pState->m_zip64)
6621 if (max_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX)
6623 pExtra_data = extra_data;
6624 if (level_and_flags & MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE)
6626 (max_size >= MZ_UINT32_MAX) ? &comp_size : NULL,
6627 (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
6631 (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
6634 if (!
mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, (mz_uint16)(extra_size + user_extra_data_len), 0, 0, 0, method, gen_flags, dos_time, dos_date))
6637 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header,
sizeof(local_dir_header)) !=
sizeof(local_dir_header))
6640 cur_archive_file_ofs +=
sizeof(local_dir_header);
6642 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
6647 cur_archive_file_ofs += archive_name_size;
6649 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, extra_data, extra_size) != extra_size)
6652 cur_archive_file_ofs += extra_size;
6656 if ((comp_size > MZ_UINT32_MAX) || (cur_archive_file_ofs > MZ_UINT32_MAX))
6658 if (!
mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, (mz_uint16)user_extra_data_len, 0, 0, 0, method, gen_flags, dos_time, dos_date))
6661 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_header,
sizeof(local_dir_header)) !=
sizeof(local_dir_header))
6664 cur_archive_file_ofs +=
sizeof(local_dir_header);
6666 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
6671 cur_archive_file_ofs += archive_name_size;
6674 if (user_extra_data_len > 0)
6676 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, user_extra_data, user_extra_data_len) != user_extra_data_len)
6679 cur_archive_file_ofs += user_extra_data_len;
6684 void *pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, MZ_ZIP_MAX_IO_BUF_SIZE);
6694 size_t n = read_callback(callback_opaque, file_ofs, pRead_buf, MZ_ZIP_MAX_IO_BUF_SIZE);
6698 if ((n > MZ_ZIP_MAX_IO_BUF_SIZE) || (file_ofs + n > max_size))
6700 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6703 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pRead_buf, n) != n)
6705 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6709 uncomp_crc32 = (mz_uint32)
mz_crc32(uncomp_crc32, (
const mz_uint8 *)pRead_buf, n);
6710 cur_archive_file_ofs += n;
6712 uncomp_size = file_ofs;
6713 comp_size = uncomp_size;
6717 mz_bool result = MZ_FALSE;
6719 tdefl_compressor *pComp = (tdefl_compressor *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1,
sizeof(tdefl_compressor));
6722 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6732 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
6733 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6739 tdefl_status status;
6740 tdefl_flush flush = TDEFL_NO_FLUSH;
6742 size_t n = read_callback(callback_opaque, file_ofs, pRead_buf, MZ_ZIP_MAX_IO_BUF_SIZE);
6743 if ((n > MZ_ZIP_MAX_IO_BUF_SIZE) || (file_ofs + n > max_size))
6750 uncomp_crc32 = (mz_uint32)
mz_crc32(uncomp_crc32, (
const mz_uint8 *)pRead_buf, n);
6752 if (pZip->m_pNeeds_keepalive != NULL && pZip->m_pNeeds_keepalive(pZip->m_pIO_opaque))
6753 flush = TDEFL_FULL_FLUSH;
6756 flush = TDEFL_FINISH;
6759 if (status == TDEFL_STATUS_DONE)
6764 else if (status != TDEFL_STATUS_OKAY)
6771 pZip->m_pFree(pZip->m_pAlloc_opaque, pComp);
6775 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6779 uncomp_size = file_ofs;
6784 pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf);
6787 if (!(level_and_flags & MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE))
6794 if (pExtra_data == NULL)
6796 if (comp_size > MZ_UINT32_MAX)
6809 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, local_dir_footer, local_dir_footer_size) != local_dir_footer_size)
6812 cur_archive_file_ofs += local_dir_footer_size;
6815 if (level_and_flags & MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE)
6817 if (pExtra_data != NULL)
6820 (max_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
6824 (mz_uint16)archive_name_size, (mz_uint16)(extra_size + user_extra_data_len),
6825 (max_size >= MZ_UINT32_MAX) ? MZ_UINT32_MAX : uncomp_size,
6826 (max_size >= MZ_UINT32_MAX) ? MZ_UINT32_MAX : comp_size,
6827 uncomp_crc32, method, gen_flags, dos_time, dos_date))
6830 cur_archive_header_file_ofs = local_dir_header_ofs;
6832 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_header_file_ofs, local_dir_header,
sizeof(local_dir_header)) !=
sizeof(local_dir_header))
6835 if (pExtra_data != NULL)
6837 cur_archive_header_file_ofs +=
sizeof(local_dir_header);
6839 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_header_file_ofs, pArchive_name, archive_name_size) != archive_name_size)
6844 cur_archive_header_file_ofs += archive_name_size;
6846 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_header_file_ofs, extra_data, extra_size) != extra_size)
6849 cur_archive_header_file_ofs += extra_size;
6853 if (pExtra_data != NULL)
6856 (uncomp_size >= MZ_UINT32_MAX) ? &comp_size : NULL, (local_dir_header_ofs >= MZ_UINT32_MAX) ? &local_dir_header_ofs : NULL);
6860 uncomp_size, comp_size, uncomp_crc32, method, gen_flags, dos_time, dos_date, local_dir_header_ofs, ext_attributes,
6861 user_extra_data_central, user_extra_data_central_len))
6864 pZip->m_total_files++;
6865 pZip->m_archive_size = cur_archive_file_ofs;
6510mz_bool
mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip,
const char *pArchive_name, mz_file_read_func read_callback,
void* callback_opaque, mz_uint64 max_size,
const MZ_TIME_T *pFile_time,
const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, {
…}
6870#ifndef MINIZ_NO_STDIO
6874 MZ_FILE *pSrc_file = (MZ_FILE *)pOpaque;
6877 if (((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (
MZ_FSEEK64(pSrc_file, (mz_int64)file_ofs, SEEK_SET))))
6880 return MZ_FREAD(pBuf, 1, n, pSrc_file);
6883mz_bool
mz_zip_writer_add_cfile(mz_zip_archive *pZip,
const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 max_size,
const MZ_TIME_T *pFile_time,
const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
6884 const char *user_extra_data, mz_uint user_extra_data_len,
const char *user_extra_data_central, mz_uint user_extra_data_central_len)
6887 user_extra_data, user_extra_data_len, user_extra_data_central, user_extra_data_central_len);
6883mz_bool
mz_zip_writer_add_cfile(mz_zip_archive *pZip,
const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 max_size,
const MZ_TIME_T *pFile_time,
const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, {
…}
6890mz_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)
6892 MZ_FILE *pSrc_file = NULL;
6893 mz_uint64 uncomp_size = 0;
6894 MZ_TIME_T file_modified_time;
6895 MZ_TIME_T *pFile_time = NULL;
6898 memset(&file_modified_time, 0,
sizeof(file_modified_time));
6900#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_STDIO)
6901 pFile_time = &file_modified_time;
6906 pSrc_file =
MZ_FOPEN(pSrc_filename,
"rb");
6914 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);
6890mz_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) {
…}
6930 if ((pUncomp_size) || (pComp_size) || (pLocal_header_ofs) || (pDisk_start))
6932 mz_uint8 new_ext_block[64];
6933 mz_uint8 *pDst = new_ext_block;
6936 pDst +=
sizeof(mz_uint16) * 2;
6941 pDst +=
sizeof(mz_uint64);
6947 pDst +=
sizeof(mz_uint64);
6950 if (pLocal_header_ofs)
6953 pDst +=
sizeof(mz_uint64);
6959 pDst +=
sizeof(mz_uint32);
6962 mz_write_le16(new_ext_block +
sizeof(mz_uint16), (mz_uint16)((pDst - new_ext_block) -
sizeof(mz_uint16) * 2));
6968 if ((pExt) && (ext_len))
6970 mz_uint32 extra_size_remaining = ext_len;
6971 const mz_uint8 *pExtra_data = pExt;
6975 mz_uint32 field_id, field_data_size, field_total_size;
6977 if (extra_size_remaining < (
sizeof(mz_uint16) * 2))
6980 field_id = MZ_READ_LE16(pExtra_data);
6981 field_data_size = MZ_READ_LE16(pExtra_data +
sizeof(mz_uint16));
6982 field_total_size = field_data_size +
sizeof(mz_uint16) * 2;
6984 if (field_total_size > extra_size_remaining)
6993 pExtra_data += field_total_size;
6994 extra_size_remaining -= field_total_size;
6995 }
while (extra_size_remaining);
7004 mz_uint n, bit_flags, num_alignment_padding_bytes, src_central_dir_following_data_size;
7005 mz_uint64 src_archive_bytes_remaining, local_dir_header_ofs;
7006 mz_uint64 cur_src_file_ofs, cur_dst_file_ofs;
7008 mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32;
7010 size_t orig_central_dir_size;
7011 mz_zip_internal_state *pState;
7013 const mz_uint8 *pSrc_central_header;
7014 mz_zip_archive_file_stat src_file_stat;
7015 mz_uint32 src_filename_len, src_comment_len, src_ext_len;
7016 mz_uint32 local_header_filename_size, local_header_extra_len;
7017 mz_uint64 local_header_comp_size, local_header_uncomp_size;
7018 mz_bool found_zip64_ext_data_in_ldir = MZ_FALSE;
7021 if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pSource_zip->m_pRead))
7024 pState = pZip->m_pState;
7027 if ((pSource_zip->m_pState->m_zip64) && (!pZip->m_pState->m_zip64))
7031 if (NULL == (pSrc_central_header =
mz_zip_get_cdh(pSource_zip, src_file_index)))
7040 src_central_dir_following_data_size = src_filename_len + src_ext_len + src_comment_len;
7048 if (!pState->m_zip64)
7050 if (pZip->m_total_files == MZ_UINT16_MAX)
7056 if (pZip->m_total_files == MZ_UINT32_MAX)
7063 cur_src_file_ofs = src_file_stat.m_local_header_ofs;
7064 cur_dst_file_ofs = pZip->m_archive_size;
7080 src_archive_bytes_remaining = src_file_stat.m_comp_size + local_header_filename_size + local_header_extra_len ;
7083 if ((local_header_extra_len) && ((local_header_comp_size == MZ_UINT32_MAX) || (local_header_uncomp_size == MZ_UINT32_MAX)))
7086 const mz_uint8 *pExtra_data;
7087 mz_uint32 extra_size_remaining = local_header_extra_len;
7095 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)
7101 pExtra_data = (
const mz_uint8 *)file_data_array.
m_p;
7105 mz_uint32 field_id, field_data_size, field_total_size;
7107 if (extra_size_remaining < (
sizeof(mz_uint16) * 2))
7113 field_id = MZ_READ_LE16(pExtra_data);
7114 field_data_size = MZ_READ_LE16(pExtra_data +
sizeof(mz_uint16));
7115 field_total_size = field_data_size +
sizeof(mz_uint16) * 2;
7117 if (field_total_size > extra_size_remaining)
7125 const mz_uint8 *pSrc_field_data = pExtra_data +
sizeof(mz_uint32);
7127 if (field_data_size <
sizeof(mz_uint64) * 2)
7133 local_header_uncomp_size = MZ_READ_LE64(pSrc_field_data);
7134 local_header_comp_size = MZ_READ_LE64(pSrc_field_data +
sizeof(mz_uint64));
7136 found_zip64_ext_data_in_ldir = MZ_TRUE;
7140 pExtra_data += field_total_size;
7141 extra_size_remaining -= field_total_size;
7142 }
while (extra_size_remaining);
7147 if (!pState->m_zip64)
7151 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) +
7154 if (approx_new_archive_size >= MZ_UINT32_MAX)
7162 cur_dst_file_ofs += num_alignment_padding_bytes;
7164 local_dir_header_ofs = cur_dst_file_ofs;
7165 if (pZip->m_file_offset_alignment)
7167 MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0);
7177 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)))))
7180 while (src_archive_bytes_remaining)
7182 n = (mz_uint)MZ_MIN((mz_uint64)MZ_ZIP_MAX_IO_BUF_SIZE, src_archive_bytes_remaining);
7183 if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, n) != n)
7185 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
7188 cur_src_file_ofs += n;
7190 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n)
7192 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
7195 cur_dst_file_ofs += n;
7197 src_archive_bytes_remaining -= n;
7205 if ((pSource_zip->m_pState->m_zip64) || (found_zip64_ext_data_in_ldir))
7214 if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, (
sizeof(mz_uint32) * 6)) != (
sizeof(mz_uint32) * 6))
7216 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
7227 if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf,
sizeof(mz_uint32) * 4) !=
sizeof(mz_uint32) * 4)
7229 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
7235 if (pZip->m_pState->m_zip64)
7238 const mz_uint8 *pSrc_descriptor = (
const mz_uint8 *)pBuf + (has_id ?
sizeof(mz_uint32) : 0);
7239 const mz_uint32 src_crc32 = MZ_READ_LE32(pSrc_descriptor);
7240 const mz_uint64 src_comp_size = MZ_READ_LE32(pSrc_descriptor +
sizeof(mz_uint32));
7241 const mz_uint64 src_uncomp_size = MZ_READ_LE32(pSrc_descriptor + 2*
sizeof(mz_uint32));
7244 mz_write_le32((mz_uint8 *)pBuf +
sizeof(mz_uint32) * 1, src_crc32);
7245 mz_write_le64((mz_uint8 *)pBuf +
sizeof(mz_uint32) * 2, src_comp_size);
7246 mz_write_le64((mz_uint8 *)pBuf +
sizeof(mz_uint32) * 4, src_uncomp_size);
7248 n =
sizeof(mz_uint32) * 6;
7253 n =
sizeof(mz_uint32) * (has_id ? 4 : 3);
7257 if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n)
7259 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
7263 cur_src_file_ofs += n;
7264 cur_dst_file_ofs += n;
7266 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
7269 orig_central_dir_size = pState->m_central_dir.m_size;
7273 if (pState->m_zip64)
7325 if (cur_dst_file_ofs > MZ_UINT32_MAX)
7328 if (local_dir_header_ofs >= MZ_UINT32_MAX)
7344 if (pState->m_central_dir.m_size >= MZ_UINT32_MAX)
7351 n = (mz_uint32)orig_central_dir_size;
7358 pZip->m_total_files++;
7359 pZip->m_archive_size = cur_dst_file_ofs;
7366 mz_zip_internal_state *pState;
7367 mz_uint64 central_dir_ofs, central_dir_size;
7370 if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING))
7373 pState = pZip->m_pState;
7375 if (pState->m_zip64)
7377 if ((mz_uint64)pState->m_central_dir.m_size >= MZ_UINT32_MAX)
7386 central_dir_ofs = 0;
7387 central_dir_size = 0;
7388 if (pZip->m_total_files)
7391 central_dir_ofs = pZip->m_archive_size;
7392 central_dir_size = pState->m_central_dir.m_size;
7393 pZip->m_central_directory_file_ofs = central_dir_ofs;
7394 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)
7397 pZip->m_archive_size += central_dir_size;
7400 if (pState->m_zip64)
7403 mz_uint64 rel_ofs_to_zip64_ecdr = pZip->m_archive_size;
7441#ifndef MINIZ_NO_STDIO
7442 if ((pState->m_pFile) && (
MZ_FFLUSH(pState->m_pFile) == EOF))
7448 pZip->m_zip_mode = MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED;
7454 if ((!ppBuf) || (!pSize))
7460 if ((!pZip) || (!pZip->m_pState))
7469 *ppBuf = pZip->m_pState->m_pMem;
7470 *pSize = pZip->m_pState->m_mem_size;
7471 pZip->m_pState->m_pMem = NULL;
7472 pZip->m_pState->m_mem_size = pZip->m_pState->m_mem_capacity = 0;
7482#ifndef MINIZ_NO_STDIO
7488mz_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)
7490 mz_bool status, created_new_archive = MZ_FALSE;
7491 mz_zip_archive zip_archive;
7493 mz_zip_error actual_err = MZ_ZIP_NO_ERROR;
7496 if ((
int)level_and_flags < 0)
7499 if ((!pZip_filename) || (!pArchive_name) || ((buf_size) && (!pBuf)) || ((comment_size) && (!pComment)) || ((level_and_flags & 0xF) >
MZ_UBER_COMPRESSION))
7502 *pErr = MZ_ZIP_INVALID_PARAMETER;
7509 *pErr = MZ_ZIP_INVALID_FILENAME;
7521 *pErr = zip_archive.m_last_error;
7525 created_new_archive = MZ_TRUE;
7530 if (!
mz_zip_reader_init_file_v2(&zip_archive, pZip_filename, level_and_flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY, 0, 0))
7533 *pErr = zip_archive.m_last_error;
7540 *pErr = zip_archive.m_last_error;
7548 status =
mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0);
7549 actual_err = zip_archive.m_last_error;
7555 actual_err = zip_archive.m_last_error;
7563 actual_err = zip_archive.m_last_error;
7568 if ((!status) && (created_new_archive))
7572 (void)ignoredStatus;
7488mz_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) {
…}
7583 mz_uint32 file_index;
7584 mz_zip_archive zip_archive;
7590 if ((!pZip_filename) || (!pArchive_name))
7593 *pErr = MZ_ZIP_INVALID_PARAMETER;
7602 *pErr = zip_archive.m_last_error;
7615 *pErr = zip_archive.m_last_error;
7633 return pZip ? pZip->m_zip_mode : MZ_ZIP_MODE_INVALID;
7638 return pZip ? pZip->m_zip_type : MZ_ZIP_TYPE_INVALID;
7643 mz_zip_error prev_err;
7646 return MZ_ZIP_INVALID_PARAMETER;
7648 prev_err = pZip->m_last_error;
7650 pZip->m_last_error = err_num;
7657 return MZ_ZIP_INVALID_PARAMETER;
7659 return pZip->m_last_error;
7669 mz_zip_error prev_err;
7672 return MZ_ZIP_INVALID_PARAMETER;
7674 prev_err = pZip->m_last_error;
7676 pZip->m_last_error = MZ_ZIP_NO_ERROR;
7684 case MZ_ZIP_NO_ERROR:
7686 case MZ_ZIP_UNDEFINED_ERROR:
7687 return "undefined error";
7688 case MZ_ZIP_TOO_MANY_FILES:
7689 return "too many files";
7690 case MZ_ZIP_FILE_TOO_LARGE:
7691 return "file too large";
7692 case MZ_ZIP_UNSUPPORTED_METHOD:
7693 return "unsupported method";
7694 case MZ_ZIP_UNSUPPORTED_ENCRYPTION:
7695 return "unsupported encryption";
7696 case MZ_ZIP_UNSUPPORTED_FEATURE:
7697 return "unsupported feature";
7698 case MZ_ZIP_FAILED_FINDING_CENTRAL_DIR:
7699 return "failed finding central directory";
7700 case MZ_ZIP_NOT_AN_ARCHIVE:
7701 return "not a ZIP archive";
7702 case MZ_ZIP_INVALID_HEADER_OR_CORRUPTED:
7703 return "invalid header or archive is corrupted";
7704 case MZ_ZIP_UNSUPPORTED_MULTIDISK:
7705 return "unsupported multidisk archive";
7706 case MZ_ZIP_DECOMPRESSION_FAILED:
7707 return "decompression failed or archive is corrupted";
7708 case MZ_ZIP_COMPRESSION_FAILED:
7709 return "compression failed";
7710 case MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE:
7711 return "unexpected decompressed size";
7712 case MZ_ZIP_CRC_CHECK_FAILED:
7713 return "CRC-32 check failed";
7714 case MZ_ZIP_UNSUPPORTED_CDIR_SIZE:
7715 return "unsupported central directory size";
7716 case MZ_ZIP_ALLOC_FAILED:
7717 return "allocation failed";
7718 case MZ_ZIP_FILE_OPEN_FAILED:
7719 return "file open failed";
7720 case MZ_ZIP_FILE_CREATE_FAILED:
7721 return "file create failed";
7722 case MZ_ZIP_FILE_WRITE_FAILED:
7723 return "file write failed";
7724 case MZ_ZIP_FILE_READ_FAILED:
7725 return "file read failed";
7726 case MZ_ZIP_FILE_CLOSE_FAILED:
7727 return "file close failed";
7728 case MZ_ZIP_FILE_SEEK_FAILED:
7729 return "file seek failed";
7730 case MZ_ZIP_FILE_STAT_FAILED:
7731 return "file stat failed";
7732 case MZ_ZIP_INVALID_PARAMETER:
7733 return "invalid parameter";
7734 case MZ_ZIP_INVALID_FILENAME:
7735 return "invalid filename";
7736 case MZ_ZIP_BUF_TOO_SMALL:
7737 return "buffer too small";
7738 case MZ_ZIP_INTERNAL_ERROR:
7739 return "internal error";
7740 case MZ_ZIP_FILE_NOT_FOUND:
7741 return "file not found";
7742 case MZ_ZIP_ARCHIVE_TOO_LARGE:
7743 return "archive is too large";
7744 case MZ_ZIP_VALIDATION_FAILED:
7745 return "validation failed";
7746 case MZ_ZIP_WRITE_CALLBACK_FAILED:
7747 return "write callback failed";
7748 case MZ_ZIP_TOTAL_ERRORS:
7749 return "total errors";
7754 return "unknown error";
7760 if ((!pZip) || (!pZip->m_pState))
7763 return pZip->m_pState->m_zip64;
7768 if ((!pZip) || (!pZip->m_pState))
7771 return pZip->m_pState->m_central_dir.m_size;
7776 return pZip ? pZip->m_total_files : 0;
7783 return pZip->m_archive_size;
7788 if ((!pZip) || (!pZip->m_pState))
7790 return pZip->m_pState->m_file_archive_start_ofs;
7795 if ((!pZip) || (!pZip->m_pState))
7797 return pZip->m_pState->m_pFile;
7802 if ((!pZip) || (!pZip->m_pState) || (!pBuf) || (!pZip->m_pRead))
7805 return pZip->m_pRead(pZip->m_pIO_opaque, file_ofs, pBuf, n);
7814 if (filename_buf_size)
7815 pFilename[0] =
'\0';
7820 if (filename_buf_size)
7822 n = MZ_MIN(n, filename_buf_size - 1);
7824 pFilename[n] =
'\0';
7839 if (pZip->m_zip_mode == MZ_ZIP_MODE_READING)
7841#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
7842 else if ((pZip->m_zip_mode == MZ_ZIP_MODE_WRITING) || (pZip->m_zip_mode == MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED))
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
#define MZ_WRITE_LE32(p, v)
#define TINFL_HUFF_DECODE(state_index, sym, pLookUp, pTree)
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)
int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len)
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 const mz_uint s_tdefl_num_probes[11]
mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pArchive_name, mz_file_read_func read_callback, void *callback_opaque, mz_uint64 max_size, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len)
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)
static const mz_uint16 s_tdefl_len_sym[256]
mz_bool mz_zip_end(mz_zip_archive *pZip)
static const mz_uint8 s_tdefl_packed_code_size_syms_swizzle[]
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)
mz_zip_reader_extract_iter_state * mz_zip_reader_extract_iter_new(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags)
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]
MINIZ_EXPORT void * miniz_def_alloc_func(void *opaque, size_t items, size_t size)
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)
MINIZ_EXPORT void * miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size)
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)
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)
#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)
static void tinfl_clear_tree(tinfl_decompressor *r)
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)
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]
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)
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 mz_bool mz_zip_reader_extract_to_mem_no_alloc1(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, const mz_zip_archive_file_stat *st)
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_inflateReset(mz_streamp pStream)
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)
size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state *pState, void *pvBuf, size_t buf_size)
MZ_FILE * mz_zip_get_cfile(mz_zip_archive *pZip)
static mz_bool mz_zip_writer_update_zip64_extension_block(mz_zip_array *pNew_ext, mz_zip_archive *pZip, const mz_uint8 *pExt, mz_uint32 ext_len, mz_uint64 *pComp_size, mz_uint64 *pUncomp_size, mz_uint64 *pLocal_header_ofs, mz_uint32 *pDisk_start)
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)
MINIZ_EXPORT void miniz_def_free_func(void *opaque, void *address)
tinfl_decompressor * tinfl_decompressor_alloc(void)
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)
mz_zip_reader_extract_iter_state * mz_zip_reader_extract_file_iter_new(mz_zip_archive *pZip, const char *pFilename, mz_uint flags)
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)
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)
@ TDEFL_MAX_SUPPORTED_HUFF_CODESIZE
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
mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 max_size, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data, mz_uint user_extra_data_len, const char *user_extra_data_central, mz_uint user_extra_data_central_len)
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)
tdefl_compressor * tdefl_compressor_alloc(void)
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)
mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state *pState)
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)
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_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
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 size_t mz_file_read_func_stdio(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n)
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