···6464void Section::clearCache() const { SD.rmdir(cachePath.c_str()); }
65656666bool Section::persistPageDataToSD() {
6767- size_t size = 0;
6868- auto localPath = epub->getSpineItem(spineIndex);
6767+ const auto localPath = epub->getSpineItem(spineIndex);
69687070- const auto html = epub->getItemContents(epub->getSpineItem(spineIndex), &size);
7171- if (!html) {
7272- Serial.println("Failed to read item contents");
7373- return false;
7474- }
7575-7676- // TODO: Would love to stream this through an XML visitor
6969+ // TODO: Should we get rid of this file all together?
7070+ // It currently saves us a bit of memory by allowing for all the inflation bits to be released
7171+ // before loading the XML parser
7772 const auto tmpHtmlPath = epub->getCachePath() + "/.tmp_" + std::to_string(spineIndex) + ".html";
7878- File f = SD.open(tmpHtmlPath.c_str(), FILE_WRITE);
7979- const auto written = f.write(html, size);
7373+ File f = SD.open(tmpHtmlPath.c_str(), FILE_WRITE, true);
7474+ bool success = epub->readItemContentsToStream(localPath, f, 1024);
8075 f.close();
8181- free(html);
82768383- Serial.printf("Wrote %d bytes to %s\n", written, tmpHtmlPath.c_str());
8484-8585- if (size != written) {
8686- Serial.println("Failed to inflate section contents to SD");
8787- SD.remove(tmpHtmlPath.c_str());
7777+ if (!success) {
7878+ Serial.println("Failed to stream item contents");
8879 return false;
8980 }
90818282+ Serial.printf("Streamed HTML to %s\n", tmpHtmlPath.c_str());
8383+9184 const auto sdTmpHtmlPath = "/sd" + tmpHtmlPath;
92859386 auto visitor =
9487 EpubHtmlParserSlim(sdTmpHtmlPath.c_str(), renderer, [this](const Page* page) { this->onPageComplete(page); });
9595- const bool success = visitor.parseAndBuildPages();
8888+ success = visitor.parseAndBuildPages();
96899790 SD.remove(tmpHtmlPath.c_str());
9891 if (!success) {
+224-57
lib/ZipFile/ZipFile.cpp
···33#include <HardwareSerial.h>
44#include <miniz.h>
5566-int libzInflateOneShot(const uint8_t* inputBuff, const size_t compSize, uint8_t* outputBuff, const size_t uncompSize) {
77- mz_stream pStream = {
88- .next_in = inputBuff,
99- .avail_in = compSize,
1010- .total_in = 0,
1111- .next_out = outputBuff,
1212- .avail_out = uncompSize,
1313- .total_out = 0,
1414- };
1515-1616- int status = 0;
1717- status = mz_inflateInit2(&pStream, -MZ_DEFAULT_WINDOW_BITS);
1818-1919- if (status != MZ_OK) {
2020- Serial.printf("inflateInit2 failed: %d\n", status);
2121- return status;
66+bool inflateOneShot(const uint8_t* inputBuf, const size_t deflatedSize, uint8_t* outputBuf, const size_t inflatedSize) {
77+ // Setup inflator
88+ const auto inflator = static_cast<tinfl_decompressor*>(malloc(sizeof(tinfl_decompressor)));
99+ if (!inflator) {
1010+ Serial.println("Failed to allocate memory for inflator");
1111+ return false;
2212 }
1313+ memset(inflator, 0, sizeof(tinfl_decompressor));
1414+ tinfl_init(inflator);
23152424- status = mz_inflate(&pStream, MZ_FINISH);
2525- if (status != MZ_STREAM_END) {
2626- Serial.printf("inflate failed: %d\n", status);
2727- return status;
2828- }
1616+ size_t inBytes = deflatedSize;
1717+ size_t outBytes = inflatedSize;
1818+ const tinfl_status status = tinfl_decompress(inflator, inputBuf, &inBytes, nullptr, outputBuf, &outBytes,
1919+ TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF);
2020+ free(inflator);
29213030- status = mz_inflateEnd(&pStream);
3131- if (status != MZ_OK) {
3232- Serial.printf("inflateEnd failed: %d\n", status);
3333- return status;
2222+ if (status != TINFL_STATUS_DONE) {
2323+ Serial.printf("tinfl_decompress() failed with status %d\n", status);
2424+ return false;
3425 }
35263636- return status;
3737-}
3838-3939-char* ZipFile::readTextFileToMemory(const char* filename, size_t* size) const {
4040- const auto data = readFileToMemory(filename, size, true);
4141- return data ? reinterpret_cast<char*>(data) : nullptr;
2727+ return true;
4228}
43294444-uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, bool trailingNullByte) const {
3030+bool ZipFile::loadFileStat(const char* filename, mz_zip_archive_file_stat* fileStat) const {
4531 mz_zip_archive zipArchive = {};
4632 const bool status = mz_zip_reader_init_file(&zipArchive, filePath.c_str(), 0);
47334834 if (!status) {
4935 Serial.printf("mz_zip_reader_init_file() failed!\nError %s\n", mz_zip_get_error_string(zipArchive.m_last_error));
5050- return nullptr;
3636+ return false;
5137 }
52385339 // find the file
···5541 if (!mz_zip_reader_locate_file_v2(&zipArchive, filename, nullptr, 0, &fileIndex)) {
5642 Serial.printf("Could not find file %s\n", filename);
5743 mz_zip_reader_end(&zipArchive);
5858- return nullptr;
4444+ return false;
5945 }
60466161- mz_zip_archive_file_stat fileStat;
6262- if (!mz_zip_reader_file_stat(&zipArchive, fileIndex, &fileStat)) {
4747+ if (!mz_zip_reader_file_stat(&zipArchive, fileIndex, fileStat)) {
6348 Serial.printf("mz_zip_reader_file_stat() failed!\nError %s\n", mz_zip_get_error_string(zipArchive.m_last_error));
6449 mz_zip_reader_end(&zipArchive);
6565- return nullptr;
5050+ return false;
6651 }
6752 mz_zip_reader_end(&zipArchive);
5353+ return true;
5454+}
68556969- uint8_t pLocalHeader[30];
7070- uint64_t fileOffset = fileStat.m_local_header_ofs;
5656+long ZipFile::getDataOffset(const mz_zip_archive_file_stat& fileStat) const {
5757+ constexpr auto localHeaderSize = 30;
71587272- // Reopen the file to manual read out delated bytes
7373- FILE* file = fopen(filePath.c_str(), "rb");
5959+ uint8_t pLocalHeader[localHeaderSize];
6060+ const uint64_t fileOffset = fileStat.m_local_header_ofs;
6161+6262+ FILE* file = fopen(filePath.c_str(), "r");
7463 fseek(file, fileOffset, SEEK_SET);
6464+ const size_t read = fread(pLocalHeader, 1, localHeaderSize, file);
6565+ fclose(file);
75667676- const size_t read = fread(pLocalHeader, 1, 30, file);
7777- if (read != 30) {
6767+ if (read != localHeaderSize) {
7868 Serial.println("Something went wrong reading the local header");
7979- fclose(file);
8080- return nullptr;
6969+ return -1;
8170 }
82718372 if (pLocalHeader[0] + (pLocalHeader[1] << 8) + (pLocalHeader[2] << 16) + (pLocalHeader[3] << 24) !=
8473 0x04034b50 /* MZ_ZIP_LOCAL_DIR_HEADER_SIG */) {
8574 Serial.println("Not a valid zip file header");
8686- fclose(file);
8787- return nullptr;
7575+ return -1;
8876 }
89779078 const uint16_t filenameLength = pLocalHeader[26] + (pLocalHeader[27] << 8);
9179 const uint16_t extraOffset = pLocalHeader[28] + (pLocalHeader[29] << 8);
9292- fileOffset += 30 + filenameLength + extraOffset;
8080+ return fileOffset + localHeaderSize + filenameLength + extraOffset;
8181+}
8282+8383+uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const bool trailingNullByte) const {
8484+ mz_zip_archive_file_stat fileStat;
8585+ if (!loadFileStat(filename, &fileStat)) {
8686+ return nullptr;
8787+ }
8888+8989+ const long fileOffset = getDataOffset(fileStat);
9090+ if (fileOffset < 0) {
9191+ return nullptr;
9292+ }
9393+9494+ FILE* file = fopen(filePath.c_str(), "rb");
9395 fseek(file, fileOffset, SEEK_SET);
94969597 const auto deflatedDataSize = static_cast<size_t>(fileStat.m_comp_size);
···9799 const auto dataSize = trailingNullByte ? inflatedDataSize + 1 : inflatedDataSize;
98100 const auto data = static_cast<uint8_t*>(malloc(dataSize));
99101100100- if (!fileStat.m_method) {
102102+ if (fileStat.m_method == MZ_NO_COMPRESSION) {
101103 // no deflation, just read content
102104 const size_t dataRead = fread(data, 1, inflatedDataSize, file);
103105 fclose(file);
106106+104107 if (dataRead != inflatedDataSize) {
105108 Serial.println("Failed to read data");
109109+ free(data);
106110 return nullptr;
107111 }
108108- } else {
112112+113113+ // Continue out of block with data set
114114+ } else if (fileStat.m_method == MZ_DEFLATED) {
109115 // Read out deflated content from file
110116 const auto deflatedData = static_cast<uint8_t*>(malloc(deflatedDataSize));
111117 if (deflatedData == nullptr) {
···116122117123 const size_t dataRead = fread(deflatedData, 1, deflatedDataSize, file);
118124 fclose(file);
125125+119126 if (dataRead != deflatedDataSize) {
120127 Serial.printf("Failed to read data, expected %d got %d\n", deflatedDataSize, dataRead);
121128 free(deflatedData);
129129+ free(data);
122130 return nullptr;
123131 }
124132125125- const int result = libzInflateOneShot(deflatedData, deflatedDataSize, data, inflatedDataSize);
133133+ bool success = inflateOneShot(deflatedData, deflatedDataSize, data, inflatedDataSize);
126134 free(deflatedData);
127127- if (result != MZ_OK) {
135135+136136+ if (!success) {
128137 Serial.println("Failed to inflate file");
138138+ free(data);
129139 return nullptr;
130140 }
141141+142142+ // Continue out of block with data set
143143+ } else {
144144+ Serial.println("Unsupported compression method");
145145+ fclose(file);
146146+ return nullptr;
131147 }
132148133133- if (trailingNullByte) {
134134- data[inflatedDataSize] = '\0';
149149+ if (trailingNullByte) data[inflatedDataSize] = '\0';
150150+ if (size) *size = inflatedDataSize;
151151+ return data;
152152+}
153153+154154+bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t chunkSize) const {
155155+ mz_zip_archive_file_stat fileStat;
156156+ if (!loadFileStat(filename, &fileStat)) {
157157+ return false;
158158+ }
159159+160160+ const long fileOffset = getDataOffset(fileStat);
161161+ if (fileOffset < 0) {
162162+ return false;
163163+ }
164164+165165+ FILE* file = fopen(filePath.c_str(), "rb");
166166+ fseek(file, fileOffset, SEEK_SET);
167167+168168+ const auto deflatedDataSize = static_cast<size_t>(fileStat.m_comp_size);
169169+ const auto inflatedDataSize = static_cast<size_t>(fileStat.m_uncomp_size);
170170+171171+ if (fileStat.m_method == MZ_NO_COMPRESSION) {
172172+ // no deflation, just read content
173173+ const auto buffer = static_cast<uint8_t*>(malloc(chunkSize));
174174+ if (!buffer) {
175175+ Serial.println("Failed to allocate memory for buffer");
176176+ fclose(file);
177177+ return false;
178178+ }
179179+180180+ size_t remaining = inflatedDataSize;
181181+ while (remaining > 0) {
182182+ const size_t dataRead = fread(buffer, 1, remaining < chunkSize ? remaining : chunkSize, file);
183183+ if (dataRead == 0) {
184184+ Serial.println("Could not read more bytes");
185185+ free(buffer);
186186+ fclose(file);
187187+ return false;
188188+ }
189189+190190+ out.write(buffer, dataRead);
191191+ remaining -= dataRead;
192192+ }
193193+194194+ fclose(file);
195195+ free(buffer);
196196+ return true;
135197 }
136136- if (size) {
137137- *size = inflatedDataSize;
198198+199199+ if (fileStat.m_method == MZ_DEFLATED) {
200200+ // Setup inflator
201201+ const auto inflator = static_cast<tinfl_decompressor*>(malloc(sizeof(tinfl_decompressor)));
202202+ if (!inflator) {
203203+ Serial.println("Failed to allocate memory for inflator");
204204+ fclose(file);
205205+ return false;
206206+ }
207207+ memset(inflator, 0, sizeof(tinfl_decompressor));
208208+ tinfl_init(inflator);
209209+210210+ // Setup file read buffer
211211+ const auto fileReadBuffer = static_cast<uint8_t*>(malloc(chunkSize));
212212+ if (!fileReadBuffer) {
213213+ Serial.println("Failed to allocate memory for zip file read buffer");
214214+ free(inflator);
215215+ fclose(file);
216216+ return false;
217217+ }
218218+219219+ const auto outputBuffer = static_cast<uint8_t*>(malloc(TINFL_LZ_DICT_SIZE));
220220+ if (!outputBuffer) {
221221+ Serial.println("Failed to allocate memory for dictionary");
222222+ free(inflator);
223223+ free(fileReadBuffer);
224224+ fclose(file);
225225+ return false;
226226+ }
227227+ memset(outputBuffer, 0, TINFL_LZ_DICT_SIZE);
228228+229229+ size_t fileRemainingBytes = deflatedDataSize;
230230+ size_t processedOutputBytes = 0;
231231+ size_t fileReadBufferFilledBytes = 0;
232232+ size_t fileReadBufferCursor = 0;
233233+ size_t outputCursor = 0; // Current offset in the circular dictionary
234234+235235+ while (true) {
236236+ // Load more compressed bytes when needed
237237+ if (fileReadBufferCursor >= fileReadBufferFilledBytes) {
238238+ if (fileRemainingBytes == 0) {
239239+ // Should not be hit, but a safe protection
240240+ break; // EOF
241241+ }
242242+243243+ fileReadBufferFilledBytes =
244244+ fread(fileReadBuffer, 1, fileRemainingBytes < chunkSize ? fileRemainingBytes : chunkSize, file);
245245+ fileRemainingBytes -= fileReadBufferFilledBytes;
246246+ fileReadBufferCursor = 0;
247247+248248+ if (fileReadBufferFilledBytes == 0) {
249249+ // Bad read
250250+ break; // EOF
251251+ }
252252+ }
253253+254254+ // Available bytes in fileReadBuffer to process
255255+ size_t inBytes = fileReadBufferFilledBytes - fileReadBufferCursor;
256256+ // Space remaining in outputBuffer
257257+ size_t outBytes = TINFL_LZ_DICT_SIZE - outputCursor;
258258+259259+ const tinfl_status status = tinfl_decompress(inflator, fileReadBuffer + fileReadBufferCursor, &inBytes,
260260+ outputBuffer, outputBuffer + outputCursor, &outBytes,
261261+ fileRemainingBytes > 0 ? TINFL_FLAG_HAS_MORE_INPUT : 0);
262262+263263+ // Update input position
264264+ fileReadBufferCursor += inBytes;
265265+266266+ // Write output chunk
267267+ if (outBytes > 0) {
268268+ processedOutputBytes += outBytes;
269269+ out.write(outputBuffer + outputCursor, outBytes);
270270+ // Update output position in buffer (with wraparound)
271271+ outputCursor = (outputCursor + outBytes) & (TINFL_LZ_DICT_SIZE - 1);
272272+ }
273273+274274+ Serial.printf("Decompressing - %d/%d deflated into %d/%d inflated\n", deflatedDataSize - fileRemainingBytes,
275275+ deflatedDataSize, processedOutputBytes, inflatedDataSize);
276276+277277+ if (status < 0) {
278278+ Serial.printf("tinfl_decompress() failed with status %d\n", status);
279279+ fclose(file);
280280+ free(outputBuffer);
281281+ free(fileReadBuffer);
282282+ free(inflator);
283283+ return false;
284284+ }
285285+286286+ if (status == TINFL_STATUS_DONE) {
287287+ Serial.println("Decompression finished");
288288+ fclose(file);
289289+ free(inflator);
290290+ free(fileReadBuffer);
291291+ free(outputBuffer);
292292+ return true;
293293+ }
294294+ }
295295+296296+ // If we get here, EOF reached without TINFL_STATUS_DONE
297297+ Serial.println("Unexpected EOF");
298298+ fclose(file);
299299+ free(outputBuffer);
300300+ free(fileReadBuffer);
301301+ free(inflator);
302302+ return false;
138303 }
139139- return data;
304304+305305+ Serial.println("Unsupported compression method");
306306+ return false;
140307}
···159159160160#ifndef MINIZ_NO_ZLIB_APIS
161161162162-#ifndef MINIZ_NO_DEFLATE_APIS
163163-164162int mz_deflateInit(mz_streamp pStream, int level) {
165163 return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY);
166164}
···275273 memset(&stream, 0, sizeof(stream));
276274277275 /* In case mz_ulong is 64-bits (argh I hate longs). */
278278- if ((mz_uint64)(source_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR;
276276+ if ((source_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR;
279277280278 stream.next_in = pSource;
281279 stream.avail_in = (mz_uint32)source_len;
···300298}
301299302300mz_ulong mz_compressBound(mz_ulong source_len) { return mz_deflateBound(NULL, source_len); }
303303-304304-#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
305305-306306-#ifndef MINIZ_NO_INFLATE_APIS
307301308302typedef struct {
309303 tinfl_decompressor m_decomp;
···486480 memset(&stream, 0, sizeof(stream));
487481488482 /* In case mz_ulong is 64-bits (argh I hate longs). */
489489- if ((mz_uint64)(*pSource_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR;
483483+ if ((*pSource_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR;
490484491485 stream.next_in = pSource;
492486 stream.avail_in = (mz_uint32)*pSource_len;
···511505 return mz_uncompress2(pDest, pDest_len, pSource, &source_len);
512506}
513507514514-#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
515515-516508const char* mz_error(int err) {
517509 static struct {
518510 int m_err;
···590582 * THE SOFTWARE.
591583 *
592584 **************************************************************************/
593593-594594-#ifndef MINIZ_NO_DEFLATE_APIS
595585596586#ifdef __cplusplus
597587extern "C" {
···680670static tdefl_sym_freq* tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq* pSyms0, tdefl_sym_freq* pSyms1) {
681671 mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2];
682672 tdefl_sym_freq *pCur_syms = pSyms0, *pNew_syms = pSyms1;
683683- MZ_CLEAR_ARR(hist);
673673+ MZ_CLEAR_OBJ(hist);
684674 for (i = 0; i < num_syms; i++) {
685675 mz_uint freq = pSyms0[i].m_key;
686676 hist[freq & 0xFF]++;
···774764 int static_table) {
775765 int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE];
776766 mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1];
777777- MZ_CLEAR_ARR(num_codes);
767767+ MZ_CLEAR_OBJ(num_codes);
778768 if (static_table) {
779769 for (i = 0; i < table_len; i++) num_codes[d->m_huff_code_sizes[table_num][i]]++;
780770 } else {
···794784795785 tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit);
796786797797- MZ_CLEAR_ARR(d->m_huff_code_sizes[table_num]);
798798- MZ_CLEAR_ARR(d->m_huff_codes[table_num]);
787787+ MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]);
788788+ MZ_CLEAR_OBJ(d->m_huff_codes[table_num]);
799789 for (i = 1, j = num_used_syms; i <= code_size_limit; i++)
800790 for (l = num_codes[i]; l > 0; l--) d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i);
801791 }
···861851 } \
862852 }
863853864864-static const mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5,
865865- 11, 4, 12, 3, 13, 2, 14, 1, 15};
854854+static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5,
855855+ 11, 4, 12, 3, 13, 2, 14, 1, 15};
866856867857static void tdefl_start_dynamic_block(tdefl_compressor* d) {
868858 int num_lit_codes, num_dist_codes, num_bit_lengths;
···976966977967 if (flags & 1) {
978968 mz_uint s0, s1, n0, n1, sym, num_extra_bits;
979979- mz_uint match_len = pLZ_codes[0];
980980- mz_uint match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8));
969969+ mz_uint match_len = pLZ_codes[0], match_dist = *(const mz_uint16*)(pLZ_codes + 1);
981970 pLZ_codes += 3;
982971983972 MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]);
···1018100710191008 if (pOutput_buf >= d->m_pOutput_buf_end) return MZ_FALSE;
1020100910211021- memcpy(pOutput_buf, &bit_buffer, sizeof(mz_uint64));
10101010+ *(mz_uint64*)pOutput_buf = bit_buffer;
10221011 pOutput_buf += (bits_in >> 3);
10231012 bit_buffer >>= (bits_in & ~7);
10241013 bits_in &= 7;
···10901079 return tdefl_compress_lz_codes(d);
10911080}
1092108110931093-static const mz_uint s_tdefl_num_probes[11] = {0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500};
10941094-10951082static int tdefl_flush_block(tdefl_compressor* d, int flush) {
10961083 mz_uint saved_bit_buf, saved_bits_in;
10971084 mz_uint8* pSaved_output_buf;
···11141101 d->m_pLZ_code_buf -= (d->m_num_flags_left == 8);
1115110211161103 if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index)) {
11171117- const mz_uint8 cmf = 0x78;
11181118- mz_uint8 flg, flevel = 3;
11191119- mz_uint header, i, mz_un = sizeof(s_tdefl_num_probes) / sizeof(mz_uint);
11201120-11211121- /* Determine compression level by reversing the process in tdefl_create_comp_flags_from_zip_params() */
11221122- for (i = 0; i < mz_un; i++)
11231123- if (s_tdefl_num_probes[i] == (d->m_flags & 0xFFF)) break;
11241124-11251125- if (i < 2)
11261126- flevel = 0;
11271127- else if (i < 6)
11281128- flevel = 1;
11291129- else if (i == 6)
11301130- flevel = 2;
11311131-11321132- header = cmf << 8 | (flevel << 6);
11331133- header += 31 - (header % 31);
11341134- flg = header & 0xFF;
11351135-11361136- TDEFL_PUT_BITS(cmf, 8);
11371137- TDEFL_PUT_BITS(flg, 8);
11041104+ TDEFL_PUT_BITS(0x78, 8);
11051105+ TDEFL_PUT_BITS(0x01, 8);
11381106 }
1139110711401108 TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1);
···15501518 mz_uint hash = (d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^
15511519 d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK];
15521520 mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(src_buf_left, TDEFL_MAX_MATCH_LEN - d->m_lookahead_size);
15531553- const mz_uint8* pSrc_end = pSrc ? pSrc + num_bytes_to_process : NULL;
15211521+ const mz_uint8* pSrc_end = pSrc + num_bytes_to_process;
15541522 src_buf_left -= num_bytes_to_process;
15551523 d->m_lookahead_size += num_bytes_to_process;
15561524 while (pSrc != pSrc_end) {
···17201688 if (tdefl_flush_block(d, flush) < 0) return d->m_prev_return_status;
17211689 d->m_finished = (flush == TDEFL_FINISH);
17221690 if (flush == TDEFL_FULL_FLUSH) {
17231723- MZ_CLEAR_ARR(d->m_hash);
17241724- MZ_CLEAR_ARR(d->m_next);
16911691+ MZ_CLEAR_OBJ(d->m_hash);
16921692+ MZ_CLEAR_OBJ(d->m_next);
17251693 d->m_dict_size = 0;
17261694 }
17271695 }
···17411709 d->m_max_probes[0] = 1 + ((flags & 0xFFF) + 2) / 3;
17421710 d->m_greedy_parsing = (flags & TDEFL_GREEDY_PARSING_FLAG) != 0;
17431711 d->m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3;
17441744- if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) MZ_CLEAR_ARR(d->m_hash);
17121712+ if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) MZ_CLEAR_OBJ(d->m_hash);
17451713 d->m_lookahead_pos = d->m_lookahead_size = d->m_dict_size = d->m_total_lz_bytes = d->m_lz_code_buf_dict_pos =
17461714 d->m_bits_in = 0;
17471715 d->m_output_flush_ofs = d->m_output_flush_remaining = d->m_finished = d->m_block_index = d->m_bit_buffer =
···17631731 d->m_pSrc = NULL;
17641732 d->m_src_buf_left = 0;
17651733 d->m_out_buf_ofs = 0;
17661766- if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) MZ_CLEAR_ARR(d->m_dict);
17341734+ if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) MZ_CLEAR_OBJ(d->m_dict);
17671735 memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0);
17681736 memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1);
17691737 return TDEFL_STATUS_OKAY;
···18361804 return out_buf.m_size;
18371805}
1838180618071807+static const mz_uint s_tdefl_num_probes[11] = {0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500};
18081808+18391809/* level may actually range from [0,10] (10 is a "hidden" max level, where we want a bit more compression and it's fine
18401810 * if throughput to fall off a cliff on some files). */
18411811mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy) {
···19411911/* Allocate the tdefl_compressor and tinfl_decompressor structures in C so that */
19421912/* non-C language bindings to tdefL_ and tinfl_ API don't need to worry about */
19431913/* structure size and allocation mechanism. */
19441944-tdefl_compressor* tdefl_compressor_alloc(void) { return (tdefl_compressor*)MZ_MALLOC(sizeof(tdefl_compressor)); }
19141914+tdefl_compressor* tdefl_compressor_alloc() { return (tdefl_compressor*)MZ_MALLOC(sizeof(tdefl_compressor)); }
1945191519461916void tdefl_compressor_free(tdefl_compressor* pComp) { MZ_FREE(pComp); }
19471917#endif
···19531923#ifdef __cplusplus
19541924}
19551925#endif
19561956-19571957-#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
19581958- /**************************************************************************
19591959- *
19601960- * Copyright 2013-2014 RAD Game Tools and Valve Software
19611961- * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
19621962- * All Rights Reserved.
19631963- *
19641964- * Permission is hereby granted, free of charge, to any person obtaining a copy
19651965- * of this software and associated documentation files (the "Software"), to deal
19661966- * in the Software without restriction, including without limitation the rights
19671967- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19681968- * copies of the Software, and to permit persons to whom the Software is
19691969- * furnished to do so, subject to the following conditions:
19701970- *
19711971- * The above copyright notice and this permission notice shall be included in
19721972- * all copies or substantial portions of the Software.
19731973- *
19741974- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19751975- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19761976- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19771977- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19781978- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19791979- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19801980- * THE SOFTWARE.
19811981- *
19821982- **************************************************************************/
19831983-19841984-#ifndef MINIZ_NO_INFLATE_APIS
19261926+/**************************************************************************
19271927+ *
19281928+ * Copyright 2013-2014 RAD Game Tools and Valve Software
19291929+ * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
19301930+ * All Rights Reserved.
19311931+ *
19321932+ * Permission is hereby granted, free of charge, to any person obtaining a copy
19331933+ * of this software and associated documentation files (the "Software"), to deal
19341934+ * in the Software without restriction, including without limitation the rights
19351935+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19361936+ * copies of the Software, and to permit persons to whom the Software is
19371937+ * furnished to do so, subject to the following conditions:
19381938+ *
19391939+ * The above copyright notice and this permission notice shall be included in
19401940+ * all copies or substantial portions of the Software.
19411941+ *
19421942+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19431943+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19441944+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19451945+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19461946+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19471947+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19481948+ * THE SOFTWARE.
19491949+ *
19501950+ **************************************************************************/
1985195119861952#ifdef __cplusplus
19871953extern "C" {
···20572023/* Huffman code by using whatever bits are currently present in the bit buffer. If this fails, it reads another byte,
20582024 * and tries again until it succeeds or until the */
20592025/* bit buffer contains >=15 bits (deflate's max. Huffman code size). */
20602060-#define TINFL_HUFF_BITBUF_FILL(state_index, pLookUp, pTree) \
20612061- do { \
20622062- temp = pLookUp[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \
20632063- if (temp >= 0) { \
20642064- code_len = temp >> 9; \
20652065- if ((code_len) && (num_bits >= code_len)) break; \
20662066- } else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \
20672067- code_len = TINFL_FAST_LOOKUP_BITS; \
20682068- do { \
20692069- temp = pTree[~temp + ((bit_buf >> code_len++) & 1)]; \
20702070- } while ((temp < 0) && (num_bits >= (code_len + 1))); \
20712071- if (temp >= 0) break; \
20722072- } \
20732073- TINFL_GET_BYTE(state_index, c); \
20742074- bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); \
20752075- num_bits += 8; \
20262026+#define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \
20272027+ do { \
20282028+ temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \
20292029+ if (temp >= 0) { \
20302030+ code_len = temp >> 9; \
20312031+ if ((code_len) && (num_bits >= code_len)) break; \
20322032+ } else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \
20332033+ code_len = TINFL_FAST_LOOKUP_BITS; \
20342034+ do { \
20352035+ temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
20362036+ } while ((temp < 0) && (num_bits >= (code_len + 1))); \
20372037+ if (temp >= 0) break; \
20382038+ } \
20392039+ TINFL_GET_BYTE(state_index, c); \
20402040+ bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); \
20412041+ num_bits += 8; \
20762042 } while (num_bits < 15);
2077204320782044/* TINFL_HUFF_DECODE() decodes the next Huffman coded symbol. It's more complex than you would initially expect because
···20862052 * the case where the user passes in 1+zillion bytes */
20872053/* following the deflate data and our non-conservative read-ahead path won't kick in here on this code. This is much
20882054 * trickier. */
20892089-#define TINFL_HUFF_DECODE(state_index, sym, pLookUp, pTree) \
20552055+#define TINFL_HUFF_DECODE(state_index, sym, pHuff) \
20902056 do { \
20912057 int temp; \
20922058 mz_uint code_len, c; \
20932059 if (num_bits < 15) { \
20942060 if ((pIn_buf_end - pIn_buf_cur) < 2) { \
20952095- TINFL_HUFF_BITBUF_FILL(state_index, pLookUp, pTree); \
20612061+ TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \
20962062 } else { \
20972063 bit_buf |= \
20982064 (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); \
···21002066 num_bits += 16; \
21012067 } \
21022068 } \
21032103- if ((temp = pLookUp[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
20692069+ if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \
21042070 code_len = temp >> 9, temp &= 511; \
21052071 else { \
21062072 code_len = TINFL_FAST_LOOKUP_BITS; \
21072073 do { \
21082108- temp = pTree[~temp + ((bit_buf >> code_len++) & 1)]; \
20742074+ temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \
21092075 } while (temp < 0); \
21102076 } \
21112077 sym = temp; \
···21142080 } \
21152081 MZ_MACRO_END
2116208221172117-static void tinfl_clear_tree(tinfl_decompressor* r) {
21182118- if (r->m_type == 0)
21192119- MZ_CLEAR_ARR(r->m_tree_0);
21202120- else if (r->m_type == 1)
21212121- MZ_CLEAR_ARR(r->m_tree_1);
21222122- else
21232123- MZ_CLEAR_ARR(r->m_tree_2);
21242124-}
21252125-21262083tinfl_status tinfl_decompress(tinfl_decompressor* r, const mz_uint8* pIn_buf_next, size_t* pIn_buf_size,
21272084 mz_uint8* pOut_buf_start, mz_uint8* pOut_buf_next, size_t* pOut_buf_size,
21282085 const mz_uint32 decomp_flags) {
21292129- static const mz_uint16 s_length_base[31] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
21302130- 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
21312131- static const mz_uint8 s_length_extra[31] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
21322132- 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0};
21332133- static const mz_uint16 s_dist_base[32] = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33,
21342134- 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537,
21352135- 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0};
21362136- static const mz_uint8 s_dist_extra[32] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
21372137- 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
20862086+ static const int s_length_base[31] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
20872087+ 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
20882088+ static const int s_length_extra[31] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
20892089+ 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0};
20902090+ static const int s_dist_base[32] = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33,
20912091+ 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537,
20922092+ 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0};
20932093+ static const int s_dist_extra[32] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
20942094+ 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
21382095 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};
21392139- static const mz_uint16 s_min_table_sizes[3] = {257, 1, 4};
21402140-21412141- mz_int16* pTrees[3];
21422142- mz_uint8* pCode_sizes[3];
20962096+ static const int s_min_table_sizes[3] = {257, 1, 4};
2143209721442098 tinfl_status status = TINFL_STATUS_FAILED;
21452099 mz_uint32 num_bits, dist, counter, num_extra;
21462100 tinfl_bit_buf_t bit_buf;
21472101 const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size;
21482148- mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next ? pOut_buf_next + *pOut_buf_size : NULL;
21022102+ mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size;
21492103 size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)
21502104 ? (size_t)-1
21512105 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1,
···21582112 return TINFL_STATUS_BAD_PARAM;
21592113 }
2160211421612161- pTrees[0] = r->m_tree_0;
21622162- pTrees[1] = r->m_tree_1;
21632163- pTrees[2] = r->m_tree_2;
21642164- pCode_sizes[0] = r->m_code_size_0;
21652165- pCode_sizes[1] = r->m_code_size_1;
21662166- pCode_sizes[2] = r->m_code_size_2;
21672167-21682115 num_bits = r->m_num_bits;
21692116 bit_buf = r->m_bit_buf;
21702117 dist = r->m_dist;
···21812128 counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8));
21822129 if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))
21832130 counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) ||
21842184- ((out_buf_size_mask + 1) < (size_t)((size_t)1 << (8U + (r->m_zhdr0 >> 4)))));
21312131+ ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4)))));
21852132 if (counter) {
21862133 TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED);
21872134 }
···22292176 TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED);
22302177 } else {
22312178 if (r->m_type == 1) {
22322232- mz_uint8* p = r->m_code_size_0;
21792179+ mz_uint8* p = r->m_tables[0].m_code_size;
22332180 mz_uint i;
22342181 r->m_table_sizes[0] = 288;
22352182 r->m_table_sizes[1] = 32;
22362236- TINFL_MEMSET(r->m_code_size_1, 5, 32);
21832183+ TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32);
22372184 for (i = 0; i <= 143; ++i) *p++ = 8;
22382185 for (; i <= 255; ++i) *p++ = 9;
22392186 for (; i <= 279; ++i) *p++ = 7;
···22432190 TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]);
22442191 r->m_table_sizes[counter] += s_min_table_sizes[counter];
22452192 }
22462246- MZ_CLEAR_ARR(r->m_code_size_2);
21932193+ MZ_CLEAR_OBJ(r->m_tables[2].m_code_size);
22472194 for (counter = 0; counter < r->m_table_sizes[2]; counter++) {
22482195 mz_uint s;
22492196 TINFL_GET_BITS(14, s, 3);
22502250- r->m_code_size_2[s_length_dezigzag[counter]] = (mz_uint8)s;
21972197+ r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s;
22512198 }
22522199 r->m_table_sizes[2] = 19;
22532200 }
22542201 for (; (int)r->m_type >= 0; r->m_type--) {
22552202 int tree_next, tree_cur;
22562256- mz_int16* pLookUp;
22572257- mz_int16* pTree;
22582258- mz_uint8* pCode_size;
22032203+ tinfl_huff_table* pTable;
22592204 mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16];
22602260- pLookUp = r->m_look_up[r->m_type];
22612261- pTree = pTrees[r->m_type];
22622262- pCode_size = pCode_sizes[r->m_type];
22632263- MZ_CLEAR_ARR(total_syms);
22642264- TINFL_MEMSET(pLookUp, 0, sizeof(r->m_look_up[0]));
22652265- tinfl_clear_tree(r);
22662266- for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pCode_size[i]]++;
22052205+ pTable = &r->m_tables[r->m_type];
22062206+ MZ_CLEAR_OBJ(total_syms);
22072207+ MZ_CLEAR_OBJ(pTable->m_look_up);
22082208+ MZ_CLEAR_OBJ(pTable->m_tree);
22092209+ for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++;
22672210 used_syms = 0, total = 0;
22682211 next_code[0] = next_code[1] = 0;
22692212 for (i = 1; i <= 15; ++i) {
···22742217 TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED);
22752218 }
22762219 for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index) {
22772277- mz_uint rev_code = 0, l, cur_code, code_size = pCode_size[sym_index];
22202220+ mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index];
22782221 if (!code_size) continue;
22792222 cur_code = next_code[code_size]++;
22802223 for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1);
22812224 if (code_size <= TINFL_FAST_LOOKUP_BITS) {
22822225 mz_int16 k = (mz_int16)((code_size << 9) | sym_index);
22832226 while (rev_code < TINFL_FAST_LOOKUP_SIZE) {
22842284- pLookUp[rev_code] = k;
22272227+ pTable->m_look_up[rev_code] = k;
22852228 rev_code += (1 << code_size);
22862229 }
22872230 continue;
22882231 }
22892289- if (0 == (tree_cur = pLookUp[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) {
22902290- pLookUp[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next;
22322232+ if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) {
22332233+ pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next;
22912234 tree_cur = tree_next;
22922235 tree_next -= 2;
22932236 }
22942237 rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1);
22952238 for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--) {
22962239 tree_cur -= ((rev_code >>= 1) & 1);
22972297- if (!pTree[-tree_cur - 1]) {
22982298- pTree[-tree_cur - 1] = (mz_int16)tree_next;
22402240+ if (!pTable->m_tree[-tree_cur - 1]) {
22412241+ pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next;
22992242 tree_cur = tree_next;
23002243 tree_next -= 2;
23012244 } else
23022302- tree_cur = pTree[-tree_cur - 1];
22452245+ tree_cur = pTable->m_tree[-tree_cur - 1];
23032246 }
23042247 tree_cur -= ((rev_code >>= 1) & 1);
23052305- pTree[-tree_cur - 1] = (mz_int16)sym_index;
22482248+ pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index;
23062249 }
23072250 if (r->m_type == 2) {
23082251 for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]);) {
23092252 mz_uint s;
23102310- TINFL_HUFF_DECODE(16, dist, r->m_look_up[2], r->m_tree_2);
22532253+ TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]);
23112254 if (dist < 16) {
23122255 r->m_len_codes[counter++] = (mz_uint8)dist;
23132256 continue;
···23242267 if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter) {
23252268 TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED);
23262269 }
23272327- TINFL_MEMCPY(r->m_code_size_0, r->m_len_codes, r->m_table_sizes[0]);
23282328- TINFL_MEMCPY(r->m_code_size_1, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
22702270+ TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]);
22712271+ TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]);
23292272 }
23302273 }
23312274 for (;;) {
23322275 mz_uint8* pSrc;
23332276 for (;;) {
23342277 if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2)) {
23352335- TINFL_HUFF_DECODE(23, counter, r->m_look_up[0], r->m_tree_0);
22782278+ TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]);
23362279 if (counter >= 256) break;
23372280 while (pOut_buf_cur >= pOut_buf_end) {
23382281 TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT);
···23542297 num_bits += 16;
23552298 }
23562299#endif
23572357- if ((sym2 = r->m_look_up[0][bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
23002300+ if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
23582301 code_len = sym2 >> 9;
23592302 else {
23602303 code_len = TINFL_FAST_LOOKUP_BITS;
23612304 do {
23622362- sym2 = r->m_tree_0[~sym2 + ((bit_buf >> code_len++) & 1)];
23052305+ sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)];
23632306 } while (sym2 < 0);
23642307 }
23652308 counter = sym2;
···23742317 num_bits += 16;
23752318 }
23762319#endif
23772377- if ((sym2 = r->m_look_up[0][bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
23202320+ if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0)
23782321 code_len = sym2 >> 9;
23792322 else {
23802323 code_len = TINFL_FAST_LOOKUP_BITS;
23812324 do {
23822382- sym2 = r->m_tree_0[~sym2 + ((bit_buf >> code_len++) & 1)];
23252325+ sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)];
23832326 } while (sym2 < 0);
23842327 }
23852328 bit_buf >>= code_len;
···24052348 counter += extra_bits;
24062349 }
2407235024082408- TINFL_HUFF_DECODE(26, dist, r->m_look_up[1], r->m_tree_1);
23512351+ TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]);
24092352 num_extra = s_dist_extra[dist];
24102353 dist = s_dist_base[dist];
24112354 if (num_extra) {
···24792422 --pIn_buf_cur;
24802423 num_bits -= 8;
24812424 }
24822482- bit_buf &= ~(~(tinfl_bit_buf_t)0 << num_bits);
24252425+ bit_buf &= (tinfl_bit_buf_t)((((mz_uint64)1) << num_bits) - (mz_uint64)1);
24832426 MZ_ASSERT(!num_bits); /* if this assert fires then we've read beyond the end of non-deflate/zlib streams with
24842427 following data (such as gzip streams). */
24852428···25102453 }
25112454 }
25122455 r->m_num_bits = num_bits;
25132513- r->m_bit_buf = bit_buf & ~(~(tinfl_bit_buf_t)0 << num_bits);
24562456+ r->m_bit_buf = bit_buf & (tinfl_bit_buf_t)((((mz_uint64)1) << num_bits) - (mz_uint64)1);
25142457 r->m_dist = dist;
25152458 r->m_counter = counter;
25162459 r->m_num_extra = num_extra;
···25992542 mz_uint8* pDict = (mz_uint8*)MZ_MALLOC(TINFL_LZ_DICT_SIZE);
26002543 size_t in_buf_ofs = 0, dict_ofs = 0;
26012544 if (!pDict) return TINFL_STATUS_FAILED;
26022602- memset(pDict, 0, TINFL_LZ_DICT_SIZE);
26032545 tinfl_init(&decomp);
26042546 for (;;) {
26052547 size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs;
···26202562}
2621256326222564#ifndef MINIZ_NO_MALLOC
26232623-tinfl_decompressor* tinfl_decompressor_alloc(void) {
25652565+tinfl_decompressor* tinfl_decompressor_alloc() {
26242566 tinfl_decompressor* pDecomp = (tinfl_decompressor*)MZ_MALLOC(sizeof(tinfl_decompressor));
26252567 if (pDecomp) tinfl_init(pDecomp);
26262568 return pDecomp;
···26322574#ifdef __cplusplus
26332575}
26342576#endif
26352635-26362636-#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
26372637- /**************************************************************************
26382638- *
26392639- * Copyright 2013-2014 RAD Game Tools and Valve Software
26402640- * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
26412641- * Copyright 2016 Martin Raiber
26422642- * All Rights Reserved.
26432643- *
26442644- * Permission is hereby granted, free of charge, to any person obtaining a copy
26452645- * of this software and associated documentation files (the "Software"), to deal
26462646- * in the Software without restriction, including without limitation the rights
26472647- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26482648- * copies of the Software, and to permit persons to whom the Software is
26492649- * furnished to do so, subject to the following conditions:
26502650- *
26512651- * The above copyright notice and this permission notice shall be included in
26522652- * all copies or substantial portions of the Software.
26532653- *
26542654- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26552655- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26562656- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26572657- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26582658- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26592659- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26602660- * THE SOFTWARE.
26612661- *
26622662- **************************************************************************/
25772577+/**************************************************************************
25782578+ *
25792579+ * Copyright 2013-2014 RAD Game Tools and Valve Software
25802580+ * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
25812581+ * Copyright 2016 Martin Raiber
25822582+ * All Rights Reserved.
25832583+ *
25842584+ * Permission is hereby granted, free of charge, to any person obtaining a copy
25852585+ * of this software and associated documentation files (the "Software"), to deal
25862586+ * in the Software without restriction, including without limitation the rights
25872587+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25882588+ * copies of the Software, and to permit persons to whom the Software is
25892589+ * furnished to do so, subject to the following conditions:
25902590+ *
25912591+ * The above copyright notice and this permission notice shall be included in
25922592+ * all copies or substantial portions of the Software.
25932593+ *
25942594+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25952595+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25962596+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25972597+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25982598+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25992599+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26002600+ * THE SOFTWARE.
26012601+ *
26022602+ **************************************************************************/
2663260326642604#ifndef MINIZ_NO_ARCHIVE_APIS
26652605···26742614#else
26752615#include <sys/stat.h>
2676261626772677-#if defined(_MSC_VER) || defined(__MINGW64__) || defined(__MINGW32__)
26782678-26792679-#ifndef WIN32_LEAN_AND_MEAN
26802680-#define WIN32_LEAN_AND_MEAN
26812681-#endif
26822682-#ifndef __cplusplus
26832683-#define MICROSOFT_WINDOWS_WINBASE_H_DEFINE_INTERLOCKED_CPLUSPLUS_OVERLOADS 0
26842684-#endif
26852685-#ifndef NOMINMAX
26862686-#define NOMINMAX
26872687-#endif
26882688-#include <windows.h>
26892689-26902690-static WCHAR* mz_utf8z_to_widechar(const char* str) {
26912691- int reqChars = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
26922692- WCHAR* wStr = (WCHAR*)malloc(reqChars * sizeof(WCHAR));
26932693- MultiByteToWideChar(CP_UTF8, 0, str, -1, wStr, reqChars);
26942694- return wStr;
26952695-}
26962696-26172617+#if defined(_MSC_VER) || defined(__MINGW64__)
26972618static FILE* mz_fopen(const char* pFilename, const char* pMode) {
26982698- WCHAR* wFilename = mz_utf8z_to_widechar(pFilename);
26992699- WCHAR* wMode = mz_utf8z_to_widechar(pMode);
27002619 FILE* pFile = NULL;
27012701- errno_t err = _wfopen_s(&pFile, wFilename, wMode);
27022702- free(wFilename);
27032703- free(wMode);
27042704- return err ? NULL : pFile;
26202620+ fopen_s(&pFile, pFilename, pMode);
26212621+ return pFile;
27052622}
27062706-27072623static FILE* mz_freopen(const char* pPath, const char* pMode, FILE* pStream) {
27082708- WCHAR* wPath = mz_utf8z_to_widechar(pPath);
27092709- WCHAR* wMode = mz_utf8z_to_widechar(pMode);
27102624 FILE* pFile = NULL;
27112711- errno_t err = _wfreopen_s(&pFile, wPath, wMode, pStream);
27122712- free(wPath);
27132713- free(wMode);
27142714- return err ? NULL : pFile;
27152715-}
27162716-27172717-#if defined(__MINGW32__)
27182718-static int mz_stat(const char* path, struct _stat* buffer) {
27192719- WCHAR* wPath = mz_utf8z_to_widechar(path);
27202720- int res = _wstat(wPath, buffer);
27212721- free(wPath);
27222722- return res;
27232723-}
27242724-#else
27252725-static int mz_stat64(const char* path, struct __stat64* buffer) {
27262726- WCHAR* wPath = mz_utf8z_to_widechar(path);
27272727- int res = _wstat64(wPath, buffer);
27282728- free(wPath);
27292729- return res;
26252625+ if (freopen_s(&pFile, pPath, pMode, pStream)) return NULL;
26262626+ return pFile;
27302627}
27312731-#endif
27322732-27332628#ifndef MINIZ_NO_TIME
27342629#include <sys/utime.h>
27352630#endif
···27392634#define MZ_FWRITE fwrite
27402635#define MZ_FTELL64 _ftelli64
27412636#define MZ_FSEEK64 _fseeki64
27422742-#if defined(__MINGW32__)
27432743-#define MZ_FILE_STAT_STRUCT _stat
27442744-#define MZ_FILE_STAT mz_stat
27452745-#else
27462637#define MZ_FILE_STAT_STRUCT _stat64
27472747-#define MZ_FILE_STAT mz_stat64
27482748-#endif
26382638+#define MZ_FILE_STAT _stat64
27492639#define MZ_FFLUSH fflush
27502640#define MZ_FREOPEN mz_freopen
27512641#define MZ_DELETE_FILE remove
27522752-27532753-#elif defined(__WATCOMC__)
26422642+#elif defined(__MINGW32__)
27542643#ifndef MINIZ_NO_TIME
27552644#include <sys/utime.h>
27562645#endif
···27582647#define MZ_FCLOSE fclose
27592648#define MZ_FREAD fread
27602649#define MZ_FWRITE fwrite
27612761-#define MZ_FTELL64 _ftelli64
27622762-#define MZ_FSEEK64 _fseeki64
27632763-#define MZ_FILE_STAT_STRUCT stat
27642764-#define MZ_FILE_STAT stat
26502650+#define MZ_FTELL64 ftello64
26512651+#define MZ_FSEEK64 fseeko64
26522652+#define MZ_FILE_STAT_STRUCT _stat
26532653+#define MZ_FILE_STAT _stat
27652654#define MZ_FFLUSH fflush
27662655#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
27672656#define MZ_DELETE_FILE remove
27682768-27692657#elif defined(__TINYC__)
27702658#ifndef MINIZ_NO_TIME
27712659#include <sys/utime.h>
···27812669#define MZ_FFLUSH fflush
27822670#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
27832671#define MZ_DELETE_FILE remove
27842784-27852672#elif defined(__USE_LARGEFILE64) /* gcc, clang */
27862673#ifndef MINIZ_NO_TIME
27872674#include <utime.h>
···27972684#define MZ_FFLUSH fflush
27982685#define MZ_FREOPEN(p, m, s) freopen64(p, m, s)
27992686#define MZ_DELETE_FILE remove
28002800-28012801-#elif defined(__APPLE__) || defined(__FreeBSD__) || (defined(__linux__) && defined(__x86_64__))
26872687+#elif defined(__APPLE__)
28022688#ifndef MINIZ_NO_TIME
28032689#include <utime.h>
28042690#endif
···29422828 mz_zip_array m_sorted_central_dir_offsets;
2943282929442830 /* The flags passed in when the archive is initially opened. */
29452945- mz_uint32 m_init_flags;
28312831+ uint32_t m_init_flags;
2946283229472833 /* MZ_TRUE if the archive has a zip64 end of central directory headers, etc. */
29482834 mz_bool m_zip64;
···32303116 }
3231311732323118 /* Give up if we've searched the entire file, or we've gone back "too far" (~64kb) */
32333233- if ((!cur_file_ofs) || ((pZip->m_archive_size - cur_file_ofs) >= ((mz_uint64)(MZ_UINT16_MAX) + record_size)))
32343234- return MZ_FALSE;
31193119+ if ((!cur_file_ofs) || ((pZip->m_archive_size - cur_file_ofs) >= (MZ_UINT16_MAX + record_size))) return MZ_FALSE;
3235312032363121 cur_file_ofs = MZ_MAX(cur_file_ofs - (sizeof(buf_u32) - 3), 0);
32373122 }
···32403125 return MZ_TRUE;
32413126}
3242312732433243-static mz_bool mz_zip_reader_eocd64_valid(mz_zip_archive* pZip, uint64_t offset, uint8_t* buf) {
32443244- if (pZip->m_pRead(pZip->m_pIO_opaque, offset, buf, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE) ==
32453245- MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE) {
32463246- if (MZ_READ_LE32(buf + MZ_ZIP64_ECDH_SIG_OFS) == MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG) {
32473247- return MZ_TRUE;
32483248- }
32493249- }
32503250-32513251- return MZ_FALSE;
32523252-}
32533253-32543128static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive* pZip, mz_uint flags) {
32553129 mz_uint cdir_size = 0, cdir_entries_on_this_disk = 0, num_this_disk = 0, cdir_disk_index = 0;
32563256- mz_uint64 cdir_ofs = 0, eocd_ofs = 0, archive_ofs = 0;
31303130+ mz_uint64 cdir_ofs = 0;
32573131 mz_int64 cur_file_ofs = 0;
32583132 const mz_uint8* p;
32593133···32793153 MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE, &cur_file_ofs))
32803154 return mz_zip_set_error(pZip, MZ_ZIP_FAILED_FINDING_CENTRAL_DIR);
3281315532823282- eocd_ofs = cur_file_ofs;
32833156 /* Read and verify the end of central directory record. */
32843157 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) !=
32853158 MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)
···32923165 if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs - MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE, pZip64_locator,
32933166 MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE) == MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE) {
32943167 if (MZ_READ_LE32(pZip64_locator + MZ_ZIP64_ECDL_SIG_OFS) == MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG) {
32953295- pZip->m_pState->m_zip64 = MZ_TRUE;
31683168+ zip64_end_of_central_dir_ofs = MZ_READ_LE64(pZip64_locator + MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS);
31693169+ if (zip64_end_of_central_dir_ofs > (pZip->m_archive_size - MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE))
31703170+ return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE);
31713171+31723172+ if (pZip->m_pRead(pZip->m_pIO_opaque, zip64_end_of_central_dir_ofs, pZip64_end_of_central_dir,
31733173+ MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE) == MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE) {
31743174+ if (MZ_READ_LE32(pZip64_end_of_central_dir + MZ_ZIP64_ECDH_SIG_OFS) ==
31753175+ MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG) {
31763176+ pZip->m_pState->m_zip64 = MZ_TRUE;
31773177+ }
31783178+ }
32963179 }
32973180 }
32983181 }
3299318233003300- if (pZip->m_pState->m_zip64) {
33013301- /* Try locating the EOCD64 right before the EOCD64 locator. This works even
33023302- * when the effective start of the zip header is not yet known. */
33033303- if (cur_file_ofs < MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE + MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE)
33043304- return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE);
33053305-33063306- zip64_end_of_central_dir_ofs =
33073307- cur_file_ofs - MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE - MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE;
33083308-33093309- if (!mz_zip_reader_eocd64_valid(pZip, zip64_end_of_central_dir_ofs, pZip64_end_of_central_dir)) {
33103310- /* That failed, try reading where the locator tells us to. */
33113311- zip64_end_of_central_dir_ofs = MZ_READ_LE64(pZip64_locator + MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS);
33123312-33133313- if (zip64_end_of_central_dir_ofs > (pZip->m_archive_size - MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE))
33143314- return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE);
33153315-33163316- if (!mz_zip_reader_eocd64_valid(pZip, zip64_end_of_central_dir_ofs, pZip64_end_of_central_dir))
33173317- return mz_zip_set_error(pZip, MZ_ZIP_NOT_AN_ARCHIVE);
33183318- }
33193319- }
33203320-33213183 pZip->m_total_files = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS);
33223184 cdir_entries_on_this_disk = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS);
33233185 num_this_disk = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_NUM_THIS_DISK_OFS);
···33653227 if (((num_this_disk | cdir_disk_index) != 0) && ((num_this_disk != 1) || (cdir_disk_index != 1)))
33663228 return mz_zip_set_error(pZip, MZ_ZIP_UNSUPPORTED_MULTIDISK);
3367322933683368- if (cdir_size < (mz_uint64)pZip->m_total_files * MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)
32303230+ if (cdir_size < pZip->m_total_files * MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)
33693231 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
3370323233713233 if ((cdir_ofs + (mz_uint64)cdir_size) > pZip->m_archive_size)
33723234 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
3373323533743374- if (eocd_ofs < cdir_ofs + cdir_size) return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
33753375-33763376- /* The end of central dir follows the central dir, unless the zip file has
33773377- * some trailing data (e.g. it is appended to an executable file). */
33783378- archive_ofs = eocd_ofs - (cdir_ofs + cdir_size);
33793379- if (pZip->m_pState->m_zip64) {
33803380- if (archive_ofs < MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE + MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE)
33813381- return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
33823382-33833383- archive_ofs -= MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE + MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIZE;
33843384- }
33853385-33863386- /* Update the archive start position, but only if not specified. */
33873387- if ((pZip->m_zip_type == MZ_ZIP_TYPE_FILE || pZip->m_zip_type == MZ_ZIP_TYPE_CFILE ||
33883388- pZip->m_zip_type == MZ_ZIP_TYPE_USER) &&
33893389- pZip->m_pState->m_file_archive_start_ofs == 0) {
33903390- pZip->m_pState->m_file_archive_start_ofs = archive_ofs;
33913391- pZip->m_archive_size -= archive_ofs;
33923392- }
33933393-33943236 pZip->m_central_directory_file_ofs = cdir_ofs;
3395323733963238 if (pZip->m_total_files) {
···35223364}
3523336535243366void mz_zip_zero_struct(mz_zip_archive* pZip) {
35253525- if (pZip) MZ_CLEAR_PTR(pZip);
33673367+ if (pZip) MZ_CLEAR_OBJ(*pZip);
35263368}
3527336935283370static mz_bool mz_zip_reader_end_internal(mz_zip_archive* pZip, mz_bool set_last_error) {
···36423484 if ((!pZip) || (!pFilename) || ((archive_size) && (archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)))
36433485 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
3644348636453645- pFile = MZ_FOPEN(pFilename, (flags & MZ_ZIP_FLAG_READ_ALLOW_WRITING) ? "r+b" : "rb");
34873487+ pFile = MZ_FOPEN(pFilename, "rb");
36463488 if (!pFile) return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED);
3647348936483490 file_size = archive_size;
···39423784 const mz_zip_array* pCentral_dir_offsets = &pState->m_central_dir_offsets;
39433785 const mz_zip_array* pCentral_dir = &pState->m_central_dir;
39443786 mz_uint32* pIndices = &MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0);
39453945- const mz_uint32 size = pZip->m_total_files;
37873787+ const uint32_t size = pZip->m_total_files;
39463788 const mz_uint filename_len = (mz_uint)strlen(pFilename);
3947378939483790 if (pIndex) *pIndex = 0;
···3954379639553797 while (l <= h) {
39563798 mz_int64 m = l + ((h - l) >> 1);
39573957- mz_uint32 file_index = pIndices[(mz_uint32)m];
37993799+ uint32_t file_index = pIndices[(uint32_t)m];
3958380039593801 int comp = mz_zip_filename_compare(pCentral_dir, pCentral_dir_offsets, file_index, pFilename, filename_len);
39603802 if (!comp) {
···40343876 return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND);
40353877}
4036387840374037-static mz_bool mz_zip_reader_extract_to_mem_no_alloc1(mz_zip_archive* pZip, mz_uint file_index, void* pBuf,
40384038- size_t buf_size, mz_uint flags, void* pUser_read_buf,
40394039- size_t user_read_buf_size, const mz_zip_archive_file_stat* st) {
38793879+mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive* pZip, mz_uint file_index, void* pBuf, size_t buf_size,
38803880+ mz_uint flags, void* pUser_read_buf, size_t user_read_buf_size) {
40403881 int status = TINFL_STATUS_DONE;
40413882 mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail;
40423883 mz_zip_archive_file_stat file_stat;
···40493890 (!pZip->m_pRead))
40503891 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
4051389240524052- if (st) {
40534053- file_stat = *st;
40544054- } else if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
40554055- return MZ_FALSE;
38933893+ if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) return MZ_FALSE;
4056389440573895 /* A directory or zero length file */
40583896 if ((file_stat.m_is_directory) || (!file_stat.m_comp_size)) return MZ_TRUE;
···40803918 if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
40813919 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
4082392040834083- cur_file_ofs += (mz_uint64)(MZ_ZIP_LOCAL_DIR_HEADER_SIZE) +
40844084- MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) +
39213921+ cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) +
40853922 MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
40863923 if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size)
40873924 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
···41724009 return status == TINFL_STATUS_DONE;
41734010}
4174401141754175-mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive* pZip, mz_uint file_index, void* pBuf, size_t buf_size,
41764176- mz_uint flags, void* pUser_read_buf, size_t user_read_buf_size) {
41774177- return mz_zip_reader_extract_to_mem_no_alloc1(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf,
41784178- user_read_buf_size, NULL);
41794179-}
41804180-41814012mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive* pZip, const char* pFilename, void* pBuf,
41824013 size_t buf_size, mz_uint flags, void* pUser_read_buf,
41834014 size_t user_read_buf_size) {
41844015 mz_uint32 file_index;
41854016 if (!mz_zip_reader_locate_file_v2(pZip, pFilename, NULL, flags, &file_index)) return MZ_FALSE;
41864186- return mz_zip_reader_extract_to_mem_no_alloc1(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf,
41874187- user_read_buf_size, NULL);
40174017+ return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf,
40184018+ user_read_buf_size);
41884019}
4189402041904021mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive* pZip, mz_uint file_index, void* pBuf, size_t buf_size,
41914022 mz_uint flags) {
41924192- return mz_zip_reader_extract_to_mem_no_alloc1(pZip, file_index, pBuf, buf_size, flags, NULL, 0, NULL);
40234023+ return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, NULL, 0);
41934024}
4194402541954026mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive* pZip, const char* pFilename, void* pBuf, size_t buf_size,
···41984029}
4199403042004031void* mz_zip_reader_extract_to_heap(mz_zip_archive* pZip, mz_uint file_index, size_t* pSize, mz_uint flags) {
42014201- mz_zip_archive_file_stat file_stat;
42024202- mz_uint64 alloc_size;
40324032+ mz_uint64 comp_size, uncomp_size, alloc_size;
40334033+ const mz_uint8* p = mz_zip_get_cdh(pZip, file_index);
42034034 void* pBuf;
4204403542054036 if (pSize) *pSize = 0;
4206403742074207- if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) return NULL;
40384038+ if (!p) {
40394039+ mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
40404040+ return NULL;
40414041+ }
4208404242094209- alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? file_stat.m_comp_size : file_stat.m_uncomp_size;
40434043+ comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS);
40444044+ uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS);
40454045+40464046+ alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size;
42104047 if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) {
42114048 mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
42124049 return NULL;
···42174054 return NULL;
42184055 }
4219405642204220- if (!mz_zip_reader_extract_to_mem_no_alloc1(pZip, file_index, pBuf, (size_t)alloc_size, flags, NULL, 0, &file_stat)) {
40574057+ if (!mz_zip_reader_extract_to_mem(pZip, file_index, pBuf, (size_t)alloc_size, flags)) {
42214058 pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
42224059 return NULL;
42234060 }
···42764113 if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG)
42774114 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
4278411542794279- cur_file_ofs += (mz_uint64)(MZ_ZIP_LOCAL_DIR_HEADER_SIZE) +
42804280- MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) +
41164116+ cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) +
42814117 MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
42824118 if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size)
42834119 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
···44894325 return NULL;
44904326 }
4491432744924492- pState->cur_file_ofs += (mz_uint64)(MZ_ZIP_LOCAL_DIR_HEADER_SIZE) +
44934493- MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) +
43284328+ pState->cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) +
44944329 MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
44954330 if ((pState->cur_file_ofs + pState->file_stat.m_comp_size) > pZip->m_archive_size) {
44964331 mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
···46264461 size_t to_copy = MZ_MIN((buf_size - copied_to_caller), pState->out_blk_remain);
4627446246284463 /* Copy data to caller's buffer */
46294629- memcpy((mz_uint8*)pvBuf + copied_to_caller, pWrite_buf_cur, to_copy);
44644464+ memcpy((uint8_t*)pvBuf + copied_to_caller, pWrite_buf_cur, to_copy);
4630446546314466#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
46324467 /* Perform CRC */
···4963479849644799mz_bool mz_zip_validate_archive(mz_zip_archive* pZip, mz_uint flags) {
49654800 mz_zip_internal_state* pState;
49664966- mz_uint32 i;
48014801+ uint32_t i;
4967480249684803 if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (!pZip->m_pRead))
49694804 return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
···4976481149774812 if (pZip->m_archive_size > MZ_UINT32_MAX) return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
49784813 } else {
48144814+ if (pZip->m_total_files >= MZ_UINT32_MAX) return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
48154815+49794816 if (pState->m_central_dir.m_size >= MZ_UINT32_MAX) return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE);
49804817 }
49814818···52805117 mz_uint64 cur_ofs = 0;
52815118 char buf[4096];
5282511952835283- MZ_CLEAR_ARR(buf);
51205120+ MZ_CLEAR_OBJ(buf);
5284512152855122 do {
52865123 size_t n = (size_t)MZ_MIN(sizeof(buf), size_to_reserve_at_beginning);
···53455182#else
53465183 if (pZip->m_pIO_opaque != pZip) return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
5347518453485348- if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE && !(flags & MZ_ZIP_FLAG_READ_ALLOW_WRITING)) {
51855185+ if (pZip->m_zip_type == MZ_ZIP_TYPE_FILE) {
53495186 if (!pFilename) return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
5350518753515188 /* Archive is being read from stdio and was originally opened only for reading. Try to reopen as writable. */
···56135450 pState->m_zip64 = MZ_TRUE;
56145451 /*return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES); */
56155452 }
56165616- if (((mz_uint64)buf_size > 0xFFFFFFFF) || (uncomp_size > 0xFFFFFFFF)) {
54535453+ if ((buf_size > 0xFFFFFFFF) || (uncomp_size > 0xFFFFFFFF)) {
56175454 pState->m_zip64 = MZ_TRUE;
56185455 /*return mz_zip_set_error(pZip, MZ_ZIP_ARCHIVE_TOO_LARGE); */
56195456 }
···56325469 time(&cur_time);
56335470 mz_zip_time_t_to_dos_time(cur_time, &dos_time, &dos_date);
56345471 }
56355635-#else
56365636- (void)last_modified;
56375472#endif /* #ifndef MINIZ_NO_TIME */
5638547356395474 if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) {
···56985533 }
56995534 cur_archive_file_ofs += num_alignment_padding_bytes;
5700553557015701- MZ_CLEAR_ARR(local_dir_header);
55365536+ MZ_CLEAR_OBJ(local_dir_header);
5702553757035538 if (!store_data_uncompressed || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) {
57045539 method = MZ_DEFLATED;
···58475682 mz_uint level_and_flags, const char* user_extra_data,
58485683 mz_uint user_extra_data_len, const char* user_extra_data_central,
58495684 mz_uint user_extra_data_central_len) {
58505850- mz_uint16 gen_flags;
56855685+ mz_uint16 gen_flags = (level_and_flags & MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE) ? 0 : MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR;
58515686 mz_uint uncomp_crc32 = MZ_CRC32_INIT, level, num_alignment_padding_bytes;
58525687 mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0;
58535688 mz_uint64 local_dir_header_ofs, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = 0, comp_size = 0;
···58595694 mz_zip_internal_state* pState;
58605695 mz_uint64 file_ofs = 0, cur_archive_header_file_ofs;
5861569656975697+ if (!(level_and_flags & MZ_ZIP_FLAG_ASCII_FILENAME)) gen_flags |= MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8;
56985698+58625699 if ((int)level_and_flags < 0) level_and_flags = MZ_DEFAULT_LEVEL;
58635700 level = level_and_flags & 0xF;
58645864-58655865- gen_flags = (level_and_flags & MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE) ? 0 : MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR;
58665866-58675867- if (!(level_and_flags & MZ_ZIP_FLAG_ASCII_FILENAME)) gen_flags |= MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8;
5868570158695702 /* Sanity checks */
58705703 if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pArchive_name) ||
···59185751 if (pFile_time) {
59195752 mz_zip_time_t_to_dos_time(*pFile_time, &dos_time, &dos_date);
59205753 }
59215921-#else
59225922- (void)pFile_time;
59235754#endif
5924575559255756 if (max_size <= 3) level = 0;
···59395770 method = MZ_DEFLATED;
59405771 }
5941577259425942- MZ_CLEAR_ARR(local_dir_header);
57735773+ MZ_CLEAR_OBJ(local_dir_header);
59435774 if (pState->m_zip64) {
59445775 if (max_size >= MZ_UINT32_MAX || local_dir_header_ofs >= MZ_UINT32_MAX) {
59455776 pExtra_data = extra_data;
···62286059#endif /* #ifndef MINIZ_NO_STDIO */
6229606062306061static mz_bool mz_zip_writer_update_zip64_extension_block(mz_zip_array* pNew_ext, mz_zip_archive* pZip,
62316231- const mz_uint8* pExt, mz_uint32 ext_len,
62326232- mz_uint64* pComp_size, mz_uint64* pUncomp_size,
62336233- mz_uint64* pLocal_header_ofs, mz_uint32* pDisk_start) {
60626062+ const mz_uint8* pExt, uint32_t ext_len, mz_uint64* pComp_size,
60636063+ mz_uint64* pUncomp_size, mz_uint64* pLocal_header_ofs,
60646064+ mz_uint32* pDisk_start) {
62346065 /* + 64 should be enough for any new zip64 data */
62356066 if (!mz_zip_array_reserve(pZip, pNew_ext, ext_len + 64, MZ_FALSE)) return mz_zip_set_error(pZip, MZ_ZIP_ALLOC_FAILED);
62366067···63746205 local_header_extra_len = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS);
63756206 local_header_comp_size = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_COMPRESSED_SIZE_OFS);
63766207 local_header_uncomp_size = MZ_READ_LE32(pLocal_header + MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS);
63776377- src_archive_bytes_remaining = src_file_stat.m_comp_size + local_header_filename_size + local_header_extra_len;
62086208+ src_archive_bytes_remaining = local_header_filename_size + local_header_extra_len + src_file_stat.m_comp_size;
6378620963796210 /* Try to find a zip64 extended information field */
63806211 if ((local_header_extra_len) &&
···6525635665266357 if (pZip->m_pState->m_zip64) {
65276358 /* dest is zip64, so upgrade the data descriptor */
65286528- const mz_uint8* pSrc_descriptor = (const mz_uint8*)pBuf + (has_id ? sizeof(mz_uint32) : 0);
65296529- const mz_uint32 src_crc32 = MZ_READ_LE32(pSrc_descriptor);
65306530- const mz_uint64 src_comp_size = MZ_READ_LE32(pSrc_descriptor + sizeof(mz_uint32));
65316531- const mz_uint64 src_uncomp_size = MZ_READ_LE32(pSrc_descriptor + 2 * sizeof(mz_uint32));
63596359+ const mz_uint32* pSrc_descriptor = (const mz_uint32*)((const mz_uint8*)pBuf + (has_id ? sizeof(mz_uint32) : 0));
63606360+ const mz_uint32 src_crc32 = pSrc_descriptor[0];
63616361+ const mz_uint64 src_comp_size = pSrc_descriptor[1];
63626362+ const mz_uint64 src_uncomp_size = pSrc_descriptor[2];
6532636365336364 mz_write_le32((mz_uint8*)pBuf, MZ_ZIP_DATA_DESCRIPTOR_ID);
65346365 mz_write_le32((mz_uint8*)pBuf + sizeof(mz_uint32) * 1, src_crc32);
···66536484 pState = pZip->m_pState;
6654648566556486 if (pState->m_zip64) {
66566656- if ((mz_uint64)pState->m_central_dir.m_size >= MZ_UINT32_MAX) return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
64876487+ if ((pZip->m_total_files > MZ_UINT32_MAX) || (pState->m_central_dir.m_size >= MZ_UINT32_MAX))
64886488+ return mz_zip_set_error(pZip, MZ_ZIP_TOO_MANY_FILES);
66576489 } else {
66586490 if ((pZip->m_total_files > MZ_UINT16_MAX) ||
66596491 ((pZip->m_archive_size + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) > MZ_UINT32_MAX))
···66786510 /* Write zip64 end of central directory header */
66796511 mz_uint64 rel_ofs_to_zip64_ecdr = pZip->m_archive_size;
6680651266816681- MZ_CLEAR_ARR(hdr);
65136513+ MZ_CLEAR_OBJ(hdr);
66826514 MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDH_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIG);
66836515 MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDH_SIZE_OF_RECORD_OFS,
66846516 MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE - sizeof(mz_uint32) - sizeof(mz_uint64));
···66956527 pZip->m_archive_size += MZ_ZIP64_END_OF_CENTRAL_DIR_HEADER_SIZE;
6696652866976529 /* Write zip64 end of central directory locator */
66986698- MZ_CLEAR_ARR(hdr);
65306530+ MZ_CLEAR_OBJ(hdr);
66996531 MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_SIG_OFS, MZ_ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIG);
67006532 MZ_WRITE_LE64(hdr + MZ_ZIP64_ECDL_REL_OFS_TO_ZIP64_ECDR_OFS, rel_ofs_to_zip64_ecdr);
67016533 MZ_WRITE_LE32(hdr + MZ_ZIP64_ECDL_TOTAL_NUMBER_OF_DISKS_OFS, 1);
···67076539 }
6708654067096541 /* Write end of central directory record */
67106710- MZ_CLEAR_ARR(hdr);
65426542+ MZ_CLEAR_OBJ(hdr);
67116543 MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_SIG_OFS, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG);
67126544 MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files));
67136545 MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS, MZ_MIN(MZ_UINT16_MAX, pZip->m_total_files));
···67946626 created_new_archive = MZ_TRUE;
67956627 } else {
67966628 /* Append to an existing archive. */
67976797- if (!mz_zip_reader_init_file_v2(
67986798- &zip_archive, pZip_filename,
67996799- level_and_flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY | MZ_ZIP_FLAG_READ_ALLOW_WRITING, 0, 0)) {
66296629+ if (!mz_zip_reader_init_file_v2(&zip_archive, pZip_filename,
66306630+ level_and_flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY, 0, 0)) {
68006631 if (pErr) *pErr = zip_archive.m_last_error;
68016632 return MZ_FALSE;
68026633 }
6803663468046804- if (!mz_zip_writer_init_from_reader_v2(&zip_archive, pZip_filename,
68056805- level_and_flags | MZ_ZIP_FLAG_READ_ALLOW_WRITING)) {
66356635+ if (!mz_zip_writer_init_from_reader_v2(&zip_archive, pZip_filename, level_and_flags)) {
68066636 if (pErr) *pErr = zip_archive.m_last_error;
6807663768086638 mz_zip_reader_end_internal(&zip_archive, MZ_FALSE);
···69836813 case MZ_ZIP_VALIDATION_FAILED:
69846814 return "validation failed";
69856815 case MZ_ZIP_WRITE_CALLBACK_FAILED:
69866986- return "write callback failed";
69876987- case MZ_ZIP_TOTAL_ERRORS:
69886988- return "total errors";
68166816+ return "write calledback failed";
69896817 default:
69906818 break;
69916819 }
+383-630
lib/miniz/miniz.h
···11-#ifndef MINIZ_EXPORT
21#define MINIZ_EXPORT
33-#endif
44-/* miniz.c 3.1.0 - public domain deflate/inflate, zlib-subset, ZIP
55- reading/writing/appending, PNG writing See "unlicense" statement at the end
66- of this file. Rich Geldreich <richgel99@gmail.com>, last updated Oct. 13,
77- 2013 Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951:
88- http://www.ietf.org/rfc/rfc1951.txt
22+/* miniz.c 2.2.0 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
33+ See "unlicense" statement at the end of this file.
44+ Rich Geldreich <richgel99@gmail.com>, last updated Oct. 13, 2013
55+ Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
961010- Most API's defined in miniz.c are optional. For example, to disable the
1111- archive related functions just define MINIZ_NO_ARCHIVE_APIS, or to get rid of
1212- all stdio usage define MINIZ_NO_STDIO (see the list below for more macros).
77+ Most API's defined in miniz.c are optional. For example, to disable the archive related functions just define
88+ MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros).
1391410 * Low-level Deflate/Inflate implementation notes:
15111616- Compression: Use the "tdefl" API's. The compressor supports raw, static,
1717- and dynamic blocks, lazy or greedy parsing, match length filtering, RLE-only,
1818- and Huffman-only streams. It performs and compresses approximately as well as
1919- zlib.
1212+ Compression: Use the "tdefl" API's. The compressor supports raw, static, and dynamic blocks, lazy or
1313+ greedy parsing, match length filtering, RLE-only, and Huffman-only streams. It performs and compresses
1414+ approximately as well as zlib.
20152121- Decompression: Use the "tinfl" API's. The entire decompressor is
2222- implemented as a single function coroutine: see tinfl_decompress(). It
2323- supports decompression into a 32KB (or larger power of 2) wrapping buffer, or
1616+ Decompression: Use the "tinfl" API's. The entire decompressor is implemented as a single function
1717+ coroutine: see tinfl_decompress(). It supports decompression into a 32KB (or larger power of 2) wrapping buffer, or
2418 into a memory block large enough to hold the entire file.
25192626- The low-level tdefl/tinfl API's do not make any use of dynamic memory
2727- allocation.
2020+ The low-level tdefl/tinfl API's do not make any use of dynamic memory allocation.
28212922 * zlib-style API notes:
30233131- miniz.c implements a fairly large subset of zlib. There's enough
3232- functionality present for it to be a drop-in zlib replacement in many apps:
2424+ miniz.c implements a fairly large subset of zlib. There's enough functionality present for it to be a drop-in
2525+ zlib replacement in many apps:
3326 The z_stream struct, optional memory allocation callbacks
3427 deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound
3528 inflateInit/inflateInit2/inflate/inflateReset/inflateEnd
3629 compress, compress2, compressBound, uncompress
3737- CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly
3838- routines. Supports raw deflate streams or standard zlib streams with adler-32
3939- checking.
3030+ CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines.
3131+ Supports raw deflate streams or standard zlib streams with adler-32 checking.
40324133 Limitations:
4242- The callback API's are not implemented yet. No support for gzip headers or
4343- zlib static dictionaries. I've tried to closely emulate zlib's various
4444- flavors of stream flushing and return status codes, but there are no
4545- guarantees that miniz.c pulls this off perfectly.
3434+ The callback API's are not implemented yet. No support for gzip headers or zlib static dictionaries.
3535+ I've tried to closely emulate zlib's various flavors of stream flushing and return status codes, but
3636+ there are no guarantees that miniz.c pulls this off perfectly.
46374747- * PNG writing: See the tdefl_write_image_to_png_file_in_memory() function,
4848- originally written by Alex Evans. Supports 1-4 bytes/pixel images.
3838+ * PNG writing: See the tdefl_write_image_to_png_file_in_memory() function, originally written by
3939+ Alex Evans. Supports 1-4 bytes/pixel images.
49405041 * ZIP archive API notes:
51425252- The ZIP archive API's where designed with simplicity and efficiency in
5353- mind, with just enough abstraction to get the job done with minimal fuss.
5454- There are simple API's to retrieve file information, read files from existing
5555- archives, create new archives, append new files to existing archives, or
5656- clone archive data from one archive to another. It supports archives located
5757- in memory or the heap, on disk (using stdio.h), or you can specify custom
5858- file read/write callbacks.
4343+ The ZIP archive API's where designed with simplicity and efficiency in mind, with just enough abstraction to
4444+ get the job done with minimal fuss. There are simple API's to retrieve file information, read files from
4545+ existing archives, create new archives, append new files to existing archives, or clone archive data from
4646+ one archive to another. It supports archives located in memory or the heap, on disk (using stdio.h),
4747+ or you can specify custom file read/write callbacks.
59486060- - Archive reading: Just call this function to read a single file from a
6161- disk archive:
4949+ - Archive reading: Just call this function to read a single file from a disk archive:
62506363- void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const
6464- char *pArchive_name, size_t *pSize, mz_uint zip_flags);
5151+ void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name,
5252+ size_t *pSize, mz_uint zip_flags);
65536666- For more complex cases, use the "mz_zip_reader" functions. Upon opening an
6767- archive, the entire central directory is located and read as-is into memory,
6868- and subsequent file access only occurs when reading individual files.
5454+ For more complex cases, use the "mz_zip_reader" functions. Upon opening an archive, the entire central
5555+ directory is located and read as-is into memory, and subsequent file access only occurs when reading individual
5656+ files.
69577070- - Archives file scanning: The simple way is to use this function to scan a
7171- loaded archive for a specific file:
5858+ - Archives file scanning: The simple way is to use this function to scan a loaded archive for a specific file:
72597373- int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName,
7474- const char *pComment, mz_uint flags);
6060+ int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
75617676- The locate operation can optionally check file comments too, which (as one
7777- example) can be used to identify multiple versions of the same file in an
7878- archive. This function uses a simple linear search through the central
6262+ The locate operation can optionally check file comments too, which (as one example) can be used to identify
6363+ multiple versions of the same file in an archive. This function uses a simple linear search through the central
7964 directory, so it's not very fast.
80658181- Alternately, you can iterate through all the files in an archive (using
8282- mz_zip_reader_get_num_files()) and retrieve detailed info on each file by
8383- calling mz_zip_reader_file_stat().
6666+ Alternately, you can iterate through all the files in an archive (using mz_zip_reader_get_num_files()) and
6767+ retrieve detailed info on each file by calling mz_zip_reader_file_stat().
84688585- - Archive creation: Use the "mz_zip_writer" functions. The ZIP writer
8686- immediately writes compressed file data to disk and builds an exact image of
8787- the central directory in memory. The central directory image is written all
8888- at once at the end of the archive file when the archive is finalized.
6969+ - Archive creation: Use the "mz_zip_writer" functions. The ZIP writer immediately writes compressed file data
7070+ to disk and builds an exact image of the central directory in memory. The central directory image is written
7171+ all at once at the end of the archive file when the archive is finalized.
89729090- The archive writer can optionally align each file's local header and file
9191- data to any power of 2 alignment, which can be useful when the archive will
9292- be read from optical media. Also, the writer supports placing arbitrary data
9393- blobs at the very beginning of ZIP archives. Archives written using either
9494- feature are still readable by any ZIP tool.
7373+ The archive writer can optionally align each file's local header and file data to any power of 2 alignment,
7474+ which can be useful when the archive will be read from optical media. Also, the writer supports placing
7575+ arbitrary data blobs at the very beginning of ZIP archives. Archives written using either feature are still
7676+ readable by any ZIP tool.
95779696- - Archive appending: The simple way to add a single file to an archive is
9797- to call this function:
7878+ - Archive appending: The simple way to add a single file to an archive is to call this function:
98799999- mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename,
100100- const char *pArchive_name, const void *pBuf, size_t buf_size, const void
101101- *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
8080+ mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name,
8181+ const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
10282103103- The archive will be created if it doesn't already exist, otherwise it'll be
104104- appended to. Note the appending is done in-place and is not an atomic
105105- operation, so if something goes wrong during the operation it's possible the
106106- archive could be left without a central directory (although the local file
107107- headers and file data will be fine, so the archive will be recoverable).
8383+ The archive will be created if it doesn't already exist, otherwise it'll be appended to.
8484+ Note the appending is done in-place and is not an atomic operation, so if something goes wrong
8585+ during the operation it's possible the archive could be left without a central directory (although the local
8686+ file headers and file data will be fine, so the archive will be recoverable).
1088710988 For more complex archive modification scenarios:
110110- 1. The safest way is to use a mz_zip_reader to read the existing archive,
111111- cloning only those bits you want to preserve into a new archive using using
112112- the mz_zip_writer_add_from_zip_reader() function (which compiles the
113113- compressed file data as-is). When you're done, delete the old archive and
114114- rename the newly written archive, and you're done. This is safe but requires
115115- a bunch of temporary disk space or heap memory.
8989+ 1. The safest way is to use a mz_zip_reader to read the existing archive, cloning only those bits you want to
9090+ preserve into a new archive using using the mz_zip_writer_add_from_zip_reader() function (which compiles the
9191+ compressed file data as-is). When you're done, delete the old archive and rename the newly written archive, and
9292+ you're done. This is safe but requires a bunch of temporary disk space or heap memory.
11693117117- 2. Or, you can convert an mz_zip_reader in-place to an mz_zip_writer using
118118- mz_zip_writer_init_from_reader(), append new files as needed, then finalize
119119- the archive which will write an updated central directory to the original
120120- archive. (This is basically what mz_zip_add_mem_to_archive_file_in_place()
121121- does.) There's a possibility that the archive's central directory could be
122122- lost with this method if anything goes wrong, though.
9494+ 2. Or, you can convert an mz_zip_reader in-place to an mz_zip_writer using mz_zip_writer_init_from_reader(),
9595+ append new files as needed, then finalize the archive which will write an updated central directory to the
9696+ original archive. (This is basically what mz_zip_add_mem_to_archive_file_in_place() does.) There's a
9797+ possibility that the archive's central directory could be lost with this method if anything goes wrong, though.
1239812499 - ZIP archive support limitations:
125125- No spanning support. Extraction functions can only handle unencrypted,
126126- stored or deflated files. Requires streams capable of seeking.
100100+ No spanning support. Extraction functions can only handle unencrypted, stored or deflated files.
101101+ Requires streams capable of seeking.
127102128128- * This is a header file library, like stb_image.c. To get only a header file,
129129- either cut and paste the below header, or create miniz.h, #define
130130- MINIZ_HEADER_FILE_ONLY, and then include miniz.c from it.
103103+ * This is a header file library, like stb_image.c. To get only a header file, either cut and paste the
104104+ below header, or create miniz.h, #define MINIZ_HEADER_FILE_ONLY, and then include miniz.c from it.
131105132132- * Important: For best perf. be sure to customize the below macros for your
133133- target platform: #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1 #define
134134- MINIZ_LITTLE_ENDIAN 1 #define MINIZ_HAS_64BIT_REGISTERS 1
106106+ * Important: For best perf. be sure to customize the below macros for your target platform:
107107+ #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
108108+ #define MINIZ_LITTLE_ENDIAN 1
109109+ #define MINIZ_HAS_64BIT_REGISTERS 1
135110136136- * On platforms using glibc, Be sure to "#define _LARGEFILE64_SOURCE 1" before
137137- including miniz.c to ensure miniz uses the 64-bit variants: fopen64(),
138138- stat64(), etc. Otherwise you won't be able to process large files (i.e.
139139- 32-bit stat() fails for me on files > 0x7FFFFFFF bytes).
111111+ * On platforms using glibc, Be sure to "#define _LARGEFILE64_SOURCE 1" before including miniz.c to ensure miniz
112112+ uses the 64-bit variants: fopen64(), stat64(), etc. Otherwise you won't be able to process large files
113113+ (i.e. 32-bit stat() fails for me on files > 0x7FFFFFFF bytes).
140114*/
141115#pragma once
142116143117/* Defines to completely disable specific portions of miniz.c:
144144- If all macros here are defined the only functionality remaining will be
145145- CRC-32 and adler-32. */
118118+ If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl. */
146119147147-/* Define MINIZ_NO_STDIO to disable all usage and any functions which rely on
148148- * stdio for file I/O. */
120120+/* Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O. */
149121/*#define MINIZ_NO_STDIO */
150122151151-/* If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able
152152- * to get the current time, or */
153153-/* get/set file times, and the C run-time funcs that get/set times won't be
154154- * called. */
155155-/* The current downside is the times written to your archives will be from 1979.
156156- */
123123+/* If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or */
124124+/* get/set file times, and the C run-time funcs that get/set times won't be called. */
125125+/* The current downside is the times written to your archives will be from 1979. */
157126/*#define MINIZ_NO_TIME */
158127159159-/* Define MINIZ_NO_DEFLATE_APIS to disable all compression API's. */
160160-/*#define MINIZ_NO_DEFLATE_APIS */
161161-162162-/* Define MINIZ_NO_INFLATE_APIS to disable all decompression API's. */
163163-/*#define MINIZ_NO_INFLATE_APIS */
164164-165128/* Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. */
166129/*#define MINIZ_NO_ARCHIVE_APIS */
167130168168-/* Define MINIZ_NO_ARCHIVE_WRITING_APIS to disable all writing related ZIP
169169- * archive API's. */
131131+/* Define MINIZ_NO_ARCHIVE_WRITING_APIS to disable all writing related ZIP archive API's. */
170132/*#define MINIZ_NO_ARCHIVE_WRITING_APIS */
171133172172-/* Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression
173173- * API's. */
134134+/* Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's. */
174135/*#define MINIZ_NO_ZLIB_APIS */
175136176176-/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent
177177- * conflicts against stock zlib. */
137137+/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib. */
178138/*#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES */
179139180140/* Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
181181- Note if MINIZ_NO_MALLOC is defined then the user must always provide custom
182182- user alloc/free/realloc callbacks to the zlib and archive API's, and a few
183183- stand-alone helper API's which don't provide custom user functions (such as
184184- tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work.
185185- */
141141+ Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
142142+ callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
143143+ functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. */
186144/*#define MINIZ_NO_MALLOC */
187145188188-#ifdef MINIZ_NO_INFLATE_APIS
189189-#define MINIZ_NO_ARCHIVE_APIS
190190-#endif
191191-192192-#ifdef MINIZ_NO_DEFLATE_APIS
193193-#define MINIZ_NO_ARCHIVE_WRITING_APIS
194194-#endif
195195-196146#if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
197197-/* TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc
198198- * on Linux */
147147+/* TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux */
199148#define MINIZ_NO_TIME
200149#endif
201150···213162#define MINIZ_X86_OR_X64_CPU 0
214163#endif
215164216216-/* Set MINIZ_LITTLE_ENDIAN only if not set */
217217-#if !defined(MINIZ_LITTLE_ENDIAN)
218218-#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
219219-220220-#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
165165+#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
221166/* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */
222167#define MINIZ_LITTLE_ENDIAN 1
223168#else
224169#define MINIZ_LITTLE_ENDIAN 0
225170#endif
226171227227-#else
228228-229229-#if MINIZ_X86_OR_X64_CPU
230230-#define MINIZ_LITTLE_ENDIAN 1
231231-#else
232232-#define MINIZ_LITTLE_ENDIAN 0
233233-#endif
234234-235235-#endif
236236-#endif
237237-238238-/* Using unaligned loads and stores causes errors when using UBSan */
239239-#if defined(__has_feature)
240240-#if __has_feature(undefined_behavior_sanitizer)
241241-#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
242242-#endif
243243-#endif
244244-245172/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES only if not set */
246173#if !defined(MINIZ_USE_UNALIGNED_LOADS_AND_STORES)
247174#if MINIZ_X86_OR_X64_CPU
248248-/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient
249249- * integer loads and stores from unaligned addresses. */
250250-#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
175175+/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned
176176+ * addresses. */
177177+#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
251178#define MINIZ_UNALIGNED_USE_MEMCPY
252179#else
253180#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
···256183257184#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || \
258185 defined(__ia64__) || defined(__x86_64__)
259259-/* Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are
260260- * reasonably fast (and don't involve compiler generated calls to helper
261261- * functions). */
186186+/* Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler
187187+ * generated calls to helper functions). */
262188#define MINIZ_HAS_64BIT_REGISTERS 1
263189#else
264190#define MINIZ_HAS_64BIT_REGISTERS 0
···270196271197/* ------------------- zlib-style API Definitions. */
272198273273-/* For more compatibility with zlib, miniz.c uses unsigned long for some
274274- * parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits! */
199199+/* For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can
200200+ * be either 32 or 64-bits! */
275201typedef unsigned long mz_ulong;
276202277277-/* mz_free() internally uses the MZ_FREE() macro (which by default calls free()
278278- * unless you've modified the MZ_MALLOC macro) to release a block allocated from
279279- * the heap. */
203203+/* mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC
204204+ * macro) to release a block allocated from the heap. */
280205MINIZ_EXPORT void mz_free(void* p);
281206282207#define MZ_ADLER32_INIT (1)
283283-/* mz_adler32() returns the initial adler-32 value to use when called with
284284- * ptr==NULL. */
208208+/* mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL. */
285209MINIZ_EXPORT mz_ulong mz_adler32(mz_ulong adler, const unsigned char* ptr, size_t buf_len);
286210287211#define MZ_CRC32_INIT (0)
288288-/* mz_crc32() returns the initial CRC-32 value to use when called with
289289- * ptr==NULL. */
212212+/* mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL. */
290213MINIZ_EXPORT mz_ulong mz_crc32(mz_ulong crc, const unsigned char* ptr, size_t buf_len);
291214292215/* Compression strategies. */
···296219#define MZ_DEFLATED 8
297220298221/* Heap allocation callbacks.
299299-Note that mz_alloc_func parameter types purposely differ from zlib's: items/size
300300-is size_t, not unsigned long. */
222222+Note that mz_alloc_func parameter types purposely differ from zlib's: items/size is size_t, not unsigned long. */
301223typedef void* (*mz_alloc_func)(void* opaque, size_t items, size_t size);
302224typedef void (*mz_free_func)(void* opaque, void* address);
303225typedef void* (*mz_realloc_func)(void* opaque, void* address, size_t items, size_t size);
304226305305-/* Compression levels: 0-9 are the standard zlib-style levels, 10 is best
306306- * possible compression (not zlib compatible, and may be very slow),
307307- * MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL. */
227227+/* Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and
228228+ * may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL. */
308229enum {
309230 MZ_NO_COMPRESSION = 0,
310231 MZ_BEST_SPEED = 1,
···314235 MZ_DEFAULT_COMPRESSION = -1
315236};
316237317317-#define MZ_VERSION "11.3.0"
318318-#define MZ_VERNUM 0xB300
319319-#define MZ_VER_MAJOR 11
320320-#define MZ_VER_MINOR 3
238238+#define MZ_VERSION "10.2.0"
239239+#define MZ_VERNUM 0xA100
240240+#define MZ_VER_MAJOR 10
241241+#define MZ_VER_MINOR 2
321242#define MZ_VER_REVISION 0
322243#define MZ_VER_SUBREVISION 0
323244324245#ifndef MINIZ_NO_ZLIB_APIS
325246326326-/* Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The
327327- * other values are for advanced use (refer to the zlib docs). */
247247+/* Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer
248248+ * to the zlib docs). */
328249enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
329250330251/* Return status codes. MZ_PARAM_ERROR is non-standard. */
···373294/* Returns the version string of miniz.c. */
374295MINIZ_EXPORT const char* mz_version(void);
375296376376-#ifndef MINIZ_NO_DEFLATE_APIS
377377-378297/* mz_deflateInit() initializes a compressor with default options: */
379298/* Parameters: */
380299/* pStream must point to an initialized mz_stream struct. */
381300/* level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION]. */
382382-/* level 1 enables a specially optimized compression function that's been
383383- * optimized purely for performance, not ratio. */
384384-/* (This special func. is currently only enabled when
385385- * MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.) */
301301+/* level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
302302+ */
303303+/* (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are
304304+ * defined.) */
386305/* Return values: */
387306/* MZ_OK on success. */
388307/* MZ_STREAM_ERROR if the stream is bogus. */
···393312/* mz_deflateInit2() is like mz_deflate(), except with more control: */
394313/* Additional parameters: */
395314/* method must be MZ_DEFLATED */
396396-/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with
397397- * zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no
398398- * header or footer) */
315315+/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or
316316+ * -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer) */
399317/* mem_level must be between [1, 9] (it's checked but ignored by miniz.c) */
400318MINIZ_EXPORT int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level,
401319 int strategy);
402320403403-/* Quickly resets a compressor without having to reallocate anything. Same as
404404- * calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2(). */
321321+/* Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by
322322+ * mz_deflateInit()/mz_deflateInit2(). */
405323MINIZ_EXPORT int mz_deflateReset(mz_streamp pStream);
406324407407-/* mz_deflate() compresses the input to output, consuming as much of the input
408408- * and producing as much output as possible. */
325325+/* mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
326326+ */
409327/* Parameters: */
410410-/* pStream is the stream to read from and write to. You must initialize/update
411411- * the next_in, avail_in, next_out, and avail_out members. */
412412-/* flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or
413413- * MZ_FINISH. */
328328+/* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and
329329+ * avail_out members. */
330330+/* flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH. */
414331/* Return values: */
415415-/* MZ_OK on success (when flushing, or if more input is needed but not
416416- * available, and/or there's more output to be written but the output buffer is
417417- * full). */
418418-/* MZ_STREAM_END if all input has been consumed and all output bytes have been
419419- * written. Don't call mz_deflate() on the stream anymore. */
332332+/* MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be
333333+ * written but the output buffer is full). */
334334+/* MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the
335335+ * stream anymore. */
420336/* MZ_STREAM_ERROR if the stream is bogus. */
421337/* MZ_PARAM_ERROR if one of the parameters is invalid. */
422422-/* MZ_BUF_ERROR if no forward progress is possible because the input and/or
423423- * output buffers are empty. (Fill up the input buffer or free up some output
424424- * space and try again.) */
338338+/* MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the
339339+ * input buffer or free up some output space and try again.) */
425340MINIZ_EXPORT int mz_deflate(mz_streamp pStream, int flush);
426341427342/* mz_deflateEnd() deinitializes a compressor: */
···430345/* MZ_STREAM_ERROR if the stream is bogus. */
431346MINIZ_EXPORT int mz_deflateEnd(mz_streamp pStream);
432347433433-/* mz_deflateBound() returns a (very) conservative upper bound on the amount of
434434- * data that could be generated by deflate(), assuming flush is set to only
435435- * MZ_NO_FLUSH or MZ_FINISH. */
348348+/* mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by
349349+ * deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH. */
436350MINIZ_EXPORT mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
437351438352/* Single-call compression functions mz_compress() and mz_compress2(): */
439439-/* Returns MZ_OK on success, or one of the error codes from mz_deflate() on
440440- * failure. */
353353+/* Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure. */
441354MINIZ_EXPORT int mz_compress(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource,
442355 mz_ulong source_len);
443356MINIZ_EXPORT int mz_compress2(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource,
444357 mz_ulong source_len, int level);
445358446446-/* mz_compressBound() returns a (very) conservative upper bound on the amount of
447447- * data that could be generated by calling mz_compress(). */
359359+/* mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling
360360+ * mz_compress(). */
448361MINIZ_EXPORT mz_ulong mz_compressBound(mz_ulong source_len);
449362450450-#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
451451-452452-#ifndef MINIZ_NO_INFLATE_APIS
453453-454363/* Initializes a decompressor. */
455364MINIZ_EXPORT int mz_inflateInit(mz_streamp pStream);
456365457457-/* mz_inflateInit2() is like mz_inflateInit() with an additional option that
458458- * controls the window size and whether or not the stream has been wrapped with
459459- * a zlib header/footer: */
460460-/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or
461461- * -MZ_DEFAULT_WINDOW_BITS (raw deflate). */
366366+/* mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not
367367+ * the stream has been wrapped with a zlib header/footer: */
368368+/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). */
462369MINIZ_EXPORT int mz_inflateInit2(mz_streamp pStream, int window_bits);
463370464464-/* Quickly resets a compressor without having to reallocate anything. Same as
465465- * calling mz_inflateEnd() followed by mz_inflateInit()/mz_inflateInit2(). */
371371+/* Quickly resets a compressor without having to reallocate anything. Same as calling mz_inflateEnd() followed by
372372+ * mz_inflateInit()/mz_inflateInit2(). */
466373MINIZ_EXPORT int mz_inflateReset(mz_streamp pStream);
467374468468-/* Decompresses the input stream to the output, consuming only as much of the
469469- * input as needed, and writing as much to the output as possible. */
375375+/* Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to
376376+ * the output as possible. */
470377/* Parameters: */
471471-/* pStream is the stream to read from and write to. You must initialize/update
472472- * the next_in, avail_in, next_out, and avail_out members. */
378378+/* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and
379379+ * avail_out members. */
473380/* flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH. */
474474-/* On the first call, if flush is MZ_FINISH it's assumed the input and output
475475- * buffers are both sized large enough to decompress the entire stream in a
476476- * single call (this is slightly faster). */
477477-/* MZ_FINISH implies that there are no more source bytes available beside
478478- * what's already in the input buffer, and that the output buffer is large
479479- * enough to hold the rest of the decompressed data. */
381381+/* On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to
382382+ * decompress the entire stream in a single call (this is slightly faster). */
383383+/* MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that
384384+ * the output buffer is large enough to hold the rest of the decompressed data. */
480385/* Return values: */
481481-/* MZ_OK on success. Either more input is needed but not available, and/or
482482- * there's more output to be written but the output buffer is full. */
483483-/* MZ_STREAM_END if all needed input has been consumed and all output bytes
484484- * have been written. For zlib streams, the adler-32 of the decompressed data
485485- * has also been verified. */
386386+/* MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the
387387+ * output buffer is full. */
388388+/* MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the
389389+ * adler-32 of the decompressed data has also been verified. */
486390/* MZ_STREAM_ERROR if the stream is bogus. */
487391/* MZ_DATA_ERROR if the deflate stream is invalid. */
488392/* MZ_PARAM_ERROR if one of the parameters is invalid. */
489489-/* MZ_BUF_ERROR if no forward progress is possible because the input buffer is
490490- * empty but the inflater needs more input to continue, or if the output buffer
491491- * is not large enough. Call mz_inflate() again */
492492-/* with more input data, or with more room in the output buffer (except when
493493- * using single call decompression, described above). */
393393+/* MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input
394394+ * to continue, or if the output buffer is not large enough. Call mz_inflate() again */
395395+/* with more input data, or with more room in the output buffer (except when using single call decompression,
396396+ * described above). */
494397MINIZ_EXPORT int mz_inflate(mz_streamp pStream, int flush);
495398496399/* Deinitializes a decompressor. */
497400MINIZ_EXPORT int mz_inflateEnd(mz_streamp pStream);
498401499402/* Single-call decompression. */
500500-/* Returns MZ_OK on success, or one of the error codes from mz_inflate() on
501501- * failure. */
403403+/* Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. */
502404MINIZ_EXPORT int mz_uncompress(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource,
503405 mz_ulong source_len);
504406MINIZ_EXPORT int mz_uncompress2(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource,
505407 mz_ulong* pSource_len);
506506-#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
507408508508-/* Returns a string description of the specified error code, or NULL if the
509509- * error code is invalid. */
409409+/* Returns a string description of the specified error code, or NULL if the error code is invalid. */
510410MINIZ_EXPORT const char* mz_error(int err);
511411512512-/* Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used
513513- * as a drop-in replacement for the subset of zlib that miniz.c supports. */
514514-/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you
515515- * use zlib in the same project. */
412412+/* Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset
413413+ * of zlib that miniz.c supports. */
414414+/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project. */
516415#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
517416typedef unsigned char Byte;
518417typedef unsigned int uInt;
···553452#define Z_FIXED MZ_FIXED
554453#define Z_DEFLATED MZ_DEFLATED
555454#define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
556556-/* See mz_alloc_func */
557557-typedef void* (*alloc_func)(void* opaque, size_t items, size_t size);
558558-/* See mz_free_func */
559559-typedef void (*free_func)(void* opaque, void* address);
560560-455455+#define alloc_func mz_alloc_func
456456+#define free_func mz_free_func
561457#define internal_state mz_internal_state
562458#define z_stream mz_stream
563563-564564-#ifndef MINIZ_NO_DEFLATE_APIS
565565-/* Compatiblity with zlib API. See called functions for documentation */
566566-static int deflateInit(mz_streamp pStream, int level) { return mz_deflateInit(pStream, level); }
567567-static int deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy) {
568568- return mz_deflateInit2(pStream, level, method, window_bits, mem_level, strategy);
569569-}
570570-static int deflateReset(mz_streamp pStream) { return mz_deflateReset(pStream); }
571571-static int deflate(mz_streamp pStream, int flush) { return mz_deflate(pStream, flush); }
572572-static int deflateEnd(mz_streamp pStream) { return mz_deflateEnd(pStream); }
573573-static mz_ulong deflateBound(mz_streamp pStream, mz_ulong source_len) { return mz_deflateBound(pStream, source_len); }
574574-static int compress(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong source_len) {
575575- return mz_compress(pDest, pDest_len, pSource, source_len);
576576-}
577577-static int compress2(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong source_len,
578578- int level) {
579579- return mz_compress2(pDest, pDest_len, pSource, source_len, level);
580580-}
581581-static mz_ulong compressBound(mz_ulong source_len) { return mz_compressBound(source_len); }
582582-#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
583583-584584-#ifndef MINIZ_NO_INFLATE_APIS
585585-/* Compatiblity with zlib API. See called functions for documentation */
586586-static int inflateInit(mz_streamp pStream) { return mz_inflateInit(pStream); }
587587-588588-static int inflateInit2(mz_streamp pStream, int window_bits) { return mz_inflateInit2(pStream, window_bits); }
589589-590590-static int inflateReset(mz_streamp pStream) { return mz_inflateReset(pStream); }
591591-592592-static int inflate(mz_streamp pStream, int flush) { return mz_inflate(pStream, flush); }
593593-594594-static int inflateEnd(mz_streamp pStream) { return mz_inflateEnd(pStream); }
595595-596596-static int uncompress(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong source_len) {
597597- return mz_uncompress(pDest, pDest_len, pSource, source_len);
598598-}
599599-600600-static int uncompress2(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong* pSource_len) {
601601- return mz_uncompress2(pDest, pDest_len, pSource, pSource_len);
602602-}
603603-#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
604604-605605-static mz_ulong crc32(mz_ulong crc, const unsigned char* ptr, size_t buf_len) { return mz_crc32(crc, ptr, buf_len); }
606606-607607-static mz_ulong adler32(mz_ulong adler, const unsigned char* ptr, size_t buf_len) {
608608- return mz_adler32(adler, ptr, buf_len);
609609-}
610610-459459+#define deflateInit mz_deflateInit
460460+#define deflateInit2 mz_deflateInit2
461461+#define deflateReset mz_deflateReset
462462+#define deflate mz_deflate
463463+#define deflateEnd mz_deflateEnd
464464+#define deflateBound mz_deflateBound
465465+#define compress mz_compress
466466+#define compress2 mz_compress2
467467+#define compressBound mz_compressBound
468468+#define inflateInit mz_inflateInit
469469+#define inflateInit2 mz_inflateInit2
470470+#define inflateReset mz_inflateReset
471471+#define inflate mz_inflate
472472+#define inflateEnd mz_inflateEnd
473473+#define uncompress mz_uncompress
474474+#define uncompress2 mz_uncompress2
475475+#define crc32 mz_crc32
476476+#define adler32 mz_adler32
611477#define MAX_WBITS 15
612478#define MAX_MEM_LEVEL 9
613613-614614-static const char* zError(int err) { return mz_error(err); }
479479+#define zError mz_error
615480#define ZLIB_VERSION MZ_VERSION
616481#define ZLIB_VERNUM MZ_VERNUM
617482#define ZLIB_VER_MAJOR MZ_VER_MAJOR
618483#define ZLIB_VER_MINOR MZ_VER_MINOR
619484#define ZLIB_VER_REVISION MZ_VER_REVISION
620485#define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
621621-622486#define zlibVersion mz_version
623487#define zlib_version mz_version()
624488#endif /* #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES */
···637501638502/* ------------------- Types and macros */
639503typedef unsigned char mz_uint8;
640640-typedef int16_t mz_int16;
641641-typedef uint16_t mz_uint16;
642642-typedef uint32_t mz_uint32;
643643-typedef uint32_t mz_uint;
504504+typedef signed short mz_int16;
505505+typedef unsigned short mz_uint16;
506506+typedef unsigned int mz_uint32;
507507+typedef unsigned int mz_uint;
644508typedef int64_t mz_int64;
645509typedef uint64_t mz_uint64;
646510typedef int mz_bool;
···648512#define MZ_FALSE (0)
649513#define MZ_TRUE (1)
650514651651-/* Works around MSVC's spammy "warning C4127: conditional expression is
652652- * constant" message. */
515515+/* Works around MSVC's spammy "warning C4127: conditional expression is constant" message. */
653516#ifdef _MSC_VER
654517#define MZ_MACRO_END while (0, 0)
655518#else
···665528666529#ifdef MINIZ_NO_TIME
667530typedef struct mz_dummy_time_t_tag {
668668- mz_uint32 m_dummy1;
669669- mz_uint32 m_dummy2;
531531+ int m_dummy;
670532} mz_dummy_time_t;
671533#define MZ_TIME_T mz_dummy_time_t
672534#else
···688550#define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b))
689551#define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b))
690552#define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
691691-#define MZ_CLEAR_ARR(obj) memset((obj), 0, sizeof(obj))
692692-#define MZ_CLEAR_PTR(obj) memset((obj), 0, sizeof(*obj))
693553694554#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
695555#define MZ_READ_LE16(p) *((const mz_uint16*)(p))
···728588#endif
729589#pragma once
730590731731-#ifndef MINIZ_NO_DEFLATE_APIS
732732-733591#ifdef __cplusplus
734592extern "C" {
735593#endif
736594/* ------------------- Low-level Compression API Definitions */
737595738738-/* Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly
739739- * slower, and raw/dynamic blocks will be output more frequently). */
740740-#ifndef TDEFL_LESS_MEMORY
596596+/* Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be
597597+ * output more frequently). */
741598#define TDEFL_LESS_MEMORY 0
742742-#endif
743599744744-/* tdefl_init() compression flags logically OR'd together (low 12 bits contain
745745- * the max. number of probes per dictionary search): */
746746-/* TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes
747747- * per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap
748748- * compression), 4095=Huffman+LZ (slowest/best compression). */
600600+/* tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary
601601+ * search): */
602602+/* TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only,
603603+ * 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression). */
749604enum { TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF };
750605751751-/* TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before
752752- * the deflate data, and the Adler-32 of the source data at the end. Otherwise,
753753- * you'll get raw deflate data. */
754754-/* TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even
755755- * when not writing zlib headers). */
756756-/* TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more
757757- * efficient lazy parsing. */
758758-/* TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's
759759- * initialization time to the minimum, but the output may vary from run to run
760760- * given the same input (depending on the contents of memory). */
761761-/* TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1)
762762- */
606606+/* TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of
607607+ * the source data at the end. Otherwise, you'll get raw deflate data. */
608608+/* TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers). */
609609+/* TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing. */
610610+/* TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the
611611+ * output may vary from run to run given the same input (depending on the contents of memory). */
612612+/* TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1) */
763613/* TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled. */
764614/* TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables. */
765615/* TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks. */
766766-/* The low 12 bits are reserved to control the max # of hash probes per
767767- * dictionary lookup (see TDEFL_MAX_PROBES_MASK). */
616616+/* The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK).
617617+ */
768618enum {
769619 TDEFL_WRITE_ZLIB_HEADER = 0x01000,
770620 TDEFL_COMPUTE_ADLER32 = 0x02000,
···777627};
778628779629/* High level compression functions: */
780780-/* tdefl_compress_mem_to_heap() compresses a block in memory to a heap block
781781- * allocated via malloc(). */
630630+/* tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc(). */
782631/* On entry: */
783632/* pSrc_buf, src_buf_len: Pointer and size of source block to compress. */
784784-/* flags: The max match finder probes (default is 128) logically OR'd against
785785- * the above flags. Higher probes are slower but improve compression. */
633633+/* flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower
634634+ * but improve compression. */
786635/* On return: */
787636/* Function returns a pointer to the compressed data, or NULL on failure. */
788788-/* *pOut_len will be set to the compressed data's size, which could be larger
789789- * than src_buf_len on uncompressible data. */
637637+/* *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data.
638638+ */
790639/* The caller must free() the returned block when it's no longer needed. */
791640MINIZ_EXPORT void* tdefl_compress_mem_to_heap(const void* pSrc_buf, size_t src_buf_len, size_t* pOut_len, int flags);
792641793793-/* tdefl_compress_mem_to_mem() compresses a block in memory to another block in
794794- * memory. */
642642+/* tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory. */
795643/* Returns 0 on failure. */
796644MINIZ_EXPORT size_t tdefl_compress_mem_to_mem(void* pOut_buf, size_t out_buf_len, const void* pSrc_buf,
797645 size_t src_buf_len, int flags);
798646799647/* Compresses an image to a compressed PNG file in memory. */
800648/* On entry: */
801801-/* pImage, w, h, and num_chans describe the image to compress. num_chans may be
802802- * 1, 2, 3, or 4. */
803803-/* The image pitch in bytes per scanline will be w*num_chans. The leftmost
804804- * pixel on the top scanline is stored first in memory. */
805805-/* level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED,
806806- * MZ_BEST_COMPRESSION, etc. or a decent default is MZ_DEFAULT_LEVEL */
807807-/* If flip is true, the image will be flipped on the Y axis (useful for OpenGL
808808- * apps). */
649649+/* pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4. */
650650+/* The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in
651651+ * memory. */
652652+/* level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc. or a decent default is
653653+ * MZ_DEFAULT_LEVEL */
654654+/* If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps). */
809655/* On return: */
810656/* Function returns a pointer to the compressed data, or NULL on failure. */
811657/* *pLen_out will be set to the size of the PNG image file. */
812812-/* The caller must mz_free() the returned heap block (which will typically be
813813- * larger than *pLen_out) when it's no longer needed. */
658658+/* The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no
659659+ * longer needed. */
814660MINIZ_EXPORT void* tdefl_write_image_to_png_file_in_memory_ex(const void* pImage, int w, int h, int num_chans,
815661 size_t* pLen_out, mz_uint level, mz_bool flip);
816662MINIZ_EXPORT void* tdefl_write_image_to_png_file_in_memory(const void* pImage, int w, int h, int num_chans,
817663 size_t* pLen_out);
818664819819-/* Output stream interface. The compressor uses this interface to write
820820- * compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time. */
665665+/* Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called
666666+ * TDEFL_OUT_BUF_SIZE at a time. */
821667typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void* pUser);
822668823823-/* tdefl_compress_mem_to_output() compresses a block to an output stream. The
824824- * above helpers use this function internally. */
669669+/* tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function
670670+ * internally. */
825671MINIZ_EXPORT mz_bool tdefl_compress_mem_to_output(const void* pBuf, size_t buf_len,
826672 tdefl_put_buf_func_ptr pPut_buf_func, void* pPut_buf_user, int flags);
827673···836682 TDEFL_MAX_MATCH_LEN = 258
837683};
838684839839-/* TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed
840840- * output block (using static/fixed Huffman codes). */
685685+/* TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman
686686+ * codes). */
841687#if TDEFL_LESS_MEMORY
842688enum {
843689 TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024,
···851697#else
852698enum {
853699 TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024,
854854- TDEFL_OUT_BUF_SIZE = (mz_uint)((TDEFL_LZ_CODE_BUF_SIZE * 13) / 10),
700700+ TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10,
855701 TDEFL_MAX_HUFF_SYMBOLS = 288,
856702 TDEFL_LZ_HASH_BITS = 15,
857703 TDEFL_LEVEL1_HASH_SIZE_MASK = 4095,
···860706};
861707#endif
862708863863-/* The low-level tdefl functions below may be used directly if the above helper
864864- * functions aren't flexible enough. The low-level functions don't make any heap
865865- * allocations, unlike the above helper functions. */
709709+/* The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The
710710+ * low-level functions don't make any heap allocations, unlike the above helper functions. */
866711typedef enum {
867712 TDEFL_STATUS_BAD_PARAM = -2,
868713 TDEFL_STATUS_PUT_BUF_FAILED = -1,
···902747} tdefl_compressor;
903748904749/* Initializes the compressor. */
905905-/* There is no corresponding deinit() function because the tdefl API's do not
906906- * dynamically allocate memory. */
907907-/* pBut_buf_func: If NULL, output data will be supplied to the specified
908908- * callback. In this case, the user should call the tdefl_compress_buffer() API
909909- * for compression. */
910910-/* If pBut_buf_func is NULL the user should always call the tdefl_compress()
911911- * API. */
912912-/* flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER,
913913- * etc.) */
750750+/* There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory. */
751751+/* pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call
752752+ * the tdefl_compress_buffer() API for compression. */
753753+/* If pBut_buf_func is NULL the user should always call the tdefl_compress() API. */
754754+/* flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.) */
914755MINIZ_EXPORT tdefl_status tdefl_init(tdefl_compressor* d, tdefl_put_buf_func_ptr pPut_buf_func, void* pPut_buf_user,
915756 int flags);
916757917917-/* Compresses a block of data, consuming as much of the specified input buffer
918918- * as possible, and writing as much compressed data to the specified output
919919- * buffer as possible. */
758758+/* Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much
759759+ * compressed data to the specified output buffer as possible. */
920760MINIZ_EXPORT tdefl_status tdefl_compress(tdefl_compressor* d, const void* pIn_buf, size_t* pIn_buf_size, void* pOut_buf,
921761 size_t* pOut_buf_size, tdefl_flush flush);
922762923923-/* tdefl_compress_buffer() is only usable when the tdefl_init() is called with a
924924- * non-NULL tdefl_put_buf_func_ptr. */
763763+/* tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr. */
925764/* tdefl_compress_buffer() always consumes the entire input buffer. */
926765MINIZ_EXPORT tdefl_status tdefl_compress_buffer(tdefl_compressor* d, const void* pIn_buf, size_t in_buf_size,
927766 tdefl_flush flush);
···930769MINIZ_EXPORT mz_uint32 tdefl_get_adler32(tdefl_compressor* d);
931770932771/* Create tdefl_compress() flags given zlib-style compression parameters. */
933933-/* level may range from [0,10] (where 10 is absolute max compression, but may be
934934- * much slower on some files) */
772772+/* level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) */
935773/* window_bits may be -15 (raw deflate) or 15 (zlib) */
936936-/* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY,
937937- * MZ_RLE, or MZ_FIXED */
774774+/* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED */
938775MINIZ_EXPORT mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
939776940777#ifndef MINIZ_NO_MALLOC
···948785#ifdef __cplusplus
949786}
950787#endif
951951-952952-#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
953788#pragma once
954789955790/* ------------------- Low-level Decompression API Definitions */
956791957957-#ifndef MINIZ_NO_INFLATE_APIS
958958-959792#ifdef __cplusplus
960793extern "C" {
961794#endif
962795/* Decompression flags used by tinfl_decompress(). */
963963-/* TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and
964964- * ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the
965965- * input is a raw deflate stream. */
966966-/* TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available
967967- * beyond the end of the supplied input buffer. If clear, the input buffer
968968- * contains all remaining input. */
969969-/* TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large
970970- * enough to hold the entire decompressed stream. If clear, the output buffer is
971971- * at least the size of the dictionary (typically 32KB). */
972972-/* TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the
973973- * decompressed bytes. */
796796+/* TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a
797797+ * valid zlib stream). Otherwise, the input is a raw deflate stream. */
798798+/* TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer.
799799+ * If clear, the input buffer contains all remaining input. */
800800+/* TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed
801801+ * stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB). */
802802+/* TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. */
974803enum {
975804 TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
976805 TINFL_FLAG_HAS_MORE_INPUT = 2,
···979808};
980809981810/* High level decompression functions: */
982982-/* tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block
983983- * allocated via malloc(). */
811811+/* tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc(). */
984812/* On entry: */
985985-/* pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data
986986- * to decompress. */
813813+/* pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress. */
987814/* On return: */
988815/* Function returns a pointer to the decompressed data, or NULL on failure. */
989989-/* *pOut_len will be set to the decompressed data's size, which could be larger
990990- * than src_buf_len on uncompressible data. */
991991-/* The caller must call mz_free() on the returned block when it's no longer
992992- * needed. */
816816+/* *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible
817817+ * data. */
818818+/* The caller must call mz_free() on the returned block when it's no longer needed. */
993819MINIZ_EXPORT void* tinfl_decompress_mem_to_heap(const void* pSrc_buf, size_t src_buf_len, size_t* pOut_len, int flags);
994820995995-/* tinfl_decompress_mem_to_mem() decompresses a block in memory to another block
996996- * in memory. */
997997-/* Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes
998998- * written on success. */
821821+/* tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory. */
822822+/* Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success. */
999823#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
1000824MINIZ_EXPORT size_t tinfl_decompress_mem_to_mem(void* pOut_buf, size_t out_buf_len, const void* pSrc_buf,
1001825 size_t src_buf_len, int flags);
100282610031003-/* tinfl_decompress_mem_to_callback() decompresses a block in memory to an
10041004- * internal 32KB buffer, and a user provided callback function will be called to
10051005- * flush the buffer. */
827827+/* tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided
828828+ * callback function will be called to flush the buffer. */
1006829/* Returns 1 on success or 0 on failure. */
1007830typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void* pUser);
1008831MINIZ_EXPORT int tinfl_decompress_mem_to_callback(const void* pIn_buf, size_t* pIn_buf_size,
···10248471025848/* Return status. */
1026849typedef enum {
10271027- /* This flags indicates the inflator needs 1 or more input bytes to make
10281028- forward progress, but the caller is indicating that no more are available.
10291029- The compressed data */
10301030- /* is probably corrupted. If you call the inflator again with more bytes it'll
10311031- try to continue processing the input but this is a BAD sign (either the
10321032- data is corrupted or you called it incorrectly). */
10331033- /* If you call it again with no input you'll just get
10341034- TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */
850850+ /* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is
851851+ indicating that no more are available. The compressed data */
852852+ /* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input
853853+ but this is a BAD sign (either the data is corrupted or you called it incorrectly). */
854854+ /* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */
1035855 TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS = -4,
103685610371037- /* This flag indicates that one or more of the input parameters was obviously
10381038- bogus. (You can try calling it again, but if you get this error the calling
10391039- code is wrong.) */
857857+ /* This flag indicates that one or more of the input parameters was obviously bogus. (You can try calling it again,
858858+ but if you get this error the calling code is wrong.) */
1040859 TINFL_STATUS_BAD_PARAM = -3,
104186010421042- /* This flags indicate the inflator is finished but the adler32 check of the
10431043- uncompressed data didn't match. If you call it again it'll return
10441044- TINFL_STATUS_DONE. */
861861+ /* This flags indicate the inflator is finished but the adler32 check of the uncompressed data didn't match. If you
862862+ call it again it'll return TINFL_STATUS_DONE. */
1045863 TINFL_STATUS_ADLER32_MISMATCH = -2,
104686410471047- /* This flags indicate the inflator has somehow failed (bad code, corrupted
10481048- input, etc.). If you call it again without resetting via tinfl_init() it
10491049- it'll just keep on returning the same status failure code. */
865865+ /* This flags indicate the inflator has somehow failed (bad code, corrupted input, etc.). If you call it again without
866866+ resetting via tinfl_init() it it'll just keep on returning the same status failure code. */
1050867 TINFL_STATUS_FAILED = -1,
10518681052869 /* Any status code less than TINFL_STATUS_DONE must indicate a failure. */
105387010541054- /* This flag indicates the inflator has returned every byte of uncompressed
10551055- data that it can, has consumed every byte that it needed, has successfully
10561056- reached the end of the deflate stream, and */
10571057- /* if zlib headers and adler32 checking enabled that it has successfully
10581058- checked the uncompressed data's adler32. If you call it again you'll just
10591059- get TINFL_STATUS_DONE over and over again. */
871871+ /* This flag indicates the inflator has returned every byte of uncompressed data that it can, has consumed every byte
872872+ that it needed, has successfully reached the end of the deflate stream, and */
873873+ /* if zlib headers and adler32 checking enabled that it has successfully checked the uncompressed data's adler32. If
874874+ you call it again you'll just get TINFL_STATUS_DONE over and over again. */
1060875 TINFL_STATUS_DONE = 0,
106187610621062- /* This flag indicates the inflator MUST have more input data (even 1 byte)
10631063- before it can make any more forward progress, or you need to clear the
10641064- TINFL_FLAG_HAS_MORE_INPUT */
10651065- /* flag on the next call if you don't have any more source data. If the source
10661066- data was somehow corrupted it's also possible (but unlikely) for the
10671067- inflator to keep on demanding input to */
877877+ /* This flag indicates the inflator MUST have more input data (even 1 byte) before it can make any more forward
878878+ progress, or you need to clear the TINFL_FLAG_HAS_MORE_INPUT */
879879+ /* flag on the next call if you don't have any more source data. If the source data was somehow corrupted it's also
880880+ possible (but unlikely) for the inflator to keep on demanding input to */
1068881 /* proceed, so be sure to properly set the TINFL_FLAG_HAS_MORE_INPUT flag. */
1069882 TINFL_STATUS_NEEDS_MORE_INPUT = 1,
107088310711071- /* This flag indicates the inflator definitely has 1 or more bytes of
10721072- uncompressed data available, but it cannot write this data into the output
10731073- buffer. */
10741074- /* Note if the source compressed data was corrupted it's possible for the
10751075- inflator to return a lot of uncompressed data to the caller. I've been
10761076- assuming you know how much uncompressed data to expect */
10771077- /* (either exact or worst case) and will stop calling the inflator and fail
10781078- after receiving too much. In pure streaming scenarios where you have no
10791079- idea how many bytes to expect this may not be possible */
884884+ /* This flag indicates the inflator definitely has 1 or more bytes of uncompressed data available, but it cannot write
885885+ this data into the output buffer. */
886886+ /* Note if the source compressed data was corrupted it's possible for the inflator to return a lot of uncompressed
887887+ data to the caller. I've been assuming you know how much uncompressed data to expect */
888888+ /* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure
889889+ streaming scenarios where you have no idea how many bytes to expect this may not be possible */
1080890 /* so I may need to add some code to address this. */
1081891 TINFL_STATUS_HAS_MORE_OUTPUT = 2
1082892} tinfl_status;
···1089899 MZ_MACRO_END
1090900#define tinfl_get_adler32(r) (r)->m_check_adler32
109190110921092-/* Main low-level decompressor coroutine function. This is the only function
10931093- * actually needed for decompression. All the other functions are just
10941094- * high-level helpers for improved usability. */
10951095-/* This is a universal API, i.e. it can be used as a building block to build any
10961096- * desired higher level decompression API. In the limit case, it can be called
10971097- * once per every byte input or output. */
902902+/* Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the
903903+ * other functions are just high-level helpers for improved usability. */
904904+/* This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API.
905905+ * In the limit case, it can be called once per every byte input or output. */
1098906MINIZ_EXPORT tinfl_status tinfl_decompress(tinfl_decompressor* r, const mz_uint8* pIn_buf_next, size_t* pIn_buf_size,
1099907 mz_uint8* pOut_buf_start, mz_uint8* pOut_buf_next, size_t* pOut_buf_size,
1100908 const mz_uint32 decomp_flags);
···1108916 TINFL_FAST_LOOKUP_BITS = 10,
1109917 TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
1110918};
919919+920920+typedef struct {
921921+ mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
922922+ mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
923923+} tinfl_huff_table;
11119241112925#if MINIZ_HAS_64BIT_REGISTERS
1113926#define TINFL_USE_64BIT_BITBUF 1
···1128941 m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES];
1129942 tinfl_bit_buf_t m_bit_buf;
1130943 size_t m_dist_from_out_buf_start;
11311131- mz_int16 m_look_up[TINFL_MAX_HUFF_TABLES][TINFL_FAST_LOOKUP_SIZE];
11321132- mz_int16 m_tree_0[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
11331133- mz_int16 m_tree_1[TINFL_MAX_HUFF_SYMBOLS_1 * 2];
11341134- mz_int16 m_tree_2[TINFL_MAX_HUFF_SYMBOLS_2 * 2];
11351135- mz_uint8 m_code_size_0[TINFL_MAX_HUFF_SYMBOLS_0];
11361136- mz_uint8 m_code_size_1[TINFL_MAX_HUFF_SYMBOLS_1];
11371137- mz_uint8 m_code_size_2[TINFL_MAX_HUFF_SYMBOLS_2];
944944+ tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
1138945 mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
1139946};
1140947···1142949}
1143950#endif
114495111451145-#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
11461146-1147952#pragma once
11489531149954/* ------------------- ZIP archive reading/writing */
···1155960#endif
11569611157962enum {
11581158- /* Note: These enums can be reduced as needed to save memory or stack space -
11591159- they are pretty conservative. */
963963+ /* Note: These enums can be reduced as needed to save memory or stack space - they are pretty conservative. */
1160964 MZ_ZIP_MAX_IO_BUF_SIZE = 64 * 1024,
1161965 MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 512,
1162966 MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 512
···1166970 /* Central directory file index. */
1167971 mz_uint32 m_file_index;
116897211691169- /* Byte offset of this entry in the archive's central directory. Note we
11701170- * currently only support up to UINT_MAX or less bytes in the central dir. */
973973+ /* Byte offset of this entry in the archive's central directory. Note we currently only support up to UINT_MAX or less
974974+ * bytes in the central dir. */
1171975 mz_uint64 m_central_dir_ofs;
11729761173977 /* These fields are copied directly from the zip's central dir. */
···1176980 mz_uint16 m_bit_flag;
1177981 mz_uint16 m_method;
1178982983983+#ifndef MINIZ_NO_TIME
984984+ MZ_TIME_T m_time;
985985+#endif
986986+1179987 /* CRC-32 of uncompressed data. */
1180988 mz_uint32 m_crc32;
11819891182990 /* File's compressed size. */
1183991 mz_uint64 m_comp_size;
118499211851185- /* File's uncompressed size. Note, I've seen some old archives where directory
11861186- * entries had 512 bytes for their uncompressed sizes, but when you try to
11871187- * unpack them you actually get 0 bytes. */
993993+ /* File's uncompressed size. Note, I've seen some old archives where directory entries had 512 bytes for their
994994+ * uncompressed sizes, but when you try to unpack them you actually get 0 bytes. */
1188995 mz_uint64 m_uncomp_size;
11899961190997 /* Zip internal and external file attributes. */
···12001007 /* MZ_TRUE if the entry appears to be a directory. */
12011008 mz_bool m_is_directory;
1202100912031203- /* MZ_TRUE if the entry uses encryption/strong encryption (which miniz_zip
12041204- * doesn't support) */
10101010+ /* MZ_TRUE if the entry uses encryption/strong encryption (which miniz_zip doesn't support) */
12051011 mz_bool m_is_encrypted;
1206101212071207- /* MZ_TRUE if the file is not encrypted, a patch file, and if it uses a
12081208- * compression method we support. */
10131013+ /* MZ_TRUE if the file is not encrypted, a patch file, and if it uses a compression method we support. */
12091014 mz_bool m_is_supported;
1210101512111016 /* Filename. If string ends in '/' it's a subdirectory entry. */
···12161021 /* Guaranteed to be zero terminated, may be truncated to fit. */
12171022 char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
1218102312191219-#ifdef MINIZ_NO_TIME
12201220- MZ_TIME_T m_padding;
12211221-#else
12221222- MZ_TIME_T m_time;
12231223-#endif
12241024} mz_zip_archive_file_stat;
1225102512261026typedef size_t (*mz_file_read_func)(void* pOpaque, mz_uint64 file_ofs, void* pBuf, size_t n);
···12421042 MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
12431043 MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
12441044 MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800,
12451245- MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG = 0x1000, /* if enabled, mz_zip_reader_locate_file() will be called on each
12461246- file as its validated to ensure the func finds the file in the
12471247- central dir (intended for testing) */
12481248- MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000, /* validate the local headers, but don't decompress the entire
12491249- file and check the crc32 */
12501250- MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000, /* always use the zip64 file format, instead of the original zip
12511251- file format with automatic switch to zip64. Use as flags
12521252- parameter with mz_zip_writer_init*_v2 */
10451045+ MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG =
10461046+ 0x1000, /* if enabled, mz_zip_reader_locate_file() will be called on each file as its validated to ensure the func
10471047+ finds the file in the central dir (intended for testing) */
10481048+ MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY =
10491049+ 0x2000, /* validate the local headers, but don't decompress the entire file and check the crc32 */
10501050+ MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000, /* always use the zip64 file format, instead of the original zip file format with
10511051+ automatic switch to zip64. Use as flags parameter with mz_zip_writer_init*_v2 */
12531052 MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000,
12541053 MZ_ZIP_FLAG_ASCII_FILENAME = 0x10000,
12551054 /*After adding a compressed file, seek back
12561055 to local file header and set the correct sizes*/
12571257- MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE = 0x20000,
12581258- MZ_ZIP_FLAG_READ_ALLOW_WRITING = 0x40000
10561056+ MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE = 0x20000
12591057} mz_zip_flags;
1260105812611059typedef enum {
···12681066 MZ_ZIP_TOTAL_TYPES
12691067} mz_zip_type;
1270106812711271-/* miniz error codes. Be sure to update mz_zip_get_error_string() if you add or
12721272- * modify this enum. */
10691069+/* miniz error codes. Be sure to update mz_zip_get_error_string() if you add or modify this enum. */
12731070typedef enum {
12741071 MZ_ZIP_NO_ERROR = 0,
12751072 MZ_ZIP_UNDEFINED_ERROR,
···13371134 mz_uint flags;
1338113513391136 int status;
13401340-11371137+#ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
11381138+ mz_uint file_crc32;
11391139+#endif
13411140 mz_uint64 read_buf_size, read_buf_ofs, read_buf_avail, comp_remaining, out_buf_ofs, cur_file_ofs;
13421141 mz_zip_archive_file_stat file_stat;
13431142 void* pRead_buf;
···1347114613481147 tinfl_decompressor inflator;
1349114813501350-#ifdef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
13511351- mz_uint padding;
13521352-#else
13531353- mz_uint file_crc32;
13541354-#endif
13551355-13561149} mz_zip_reader_extract_iter_state;
1357115013581151/* -------- ZIP reading */
···13661159#ifndef MINIZ_NO_STDIO
13671160/* Read a archive from a disk file. */
13681161/* file_start_ofs is the file offset where the archive actually begins, or 0. */
13691369-/* actual_archive_size is the true total size of the archive, which may be
13701370- * smaller than the file's actual size on disk. If zero the entire file is
13711371- * treated as the archive. */
11621162+/* actual_archive_size is the true total size of the archive, which may be smaller than the file's actual size on disk.
11631163+ * If zero the entire file is treated as the archive. */
13721164MINIZ_EXPORT mz_bool mz_zip_reader_init_file(mz_zip_archive* pZip, const char* pFilename, mz_uint32 flags);
13731165MINIZ_EXPORT mz_bool mz_zip_reader_init_file_v2(mz_zip_archive* pZip, const char* pFilename, mz_uint flags,
13741166 mz_uint64 file_start_ofs, mz_uint64 archive_size);
1375116713761376-/* Read an archive from an already opened FILE, beginning at the current file
13771377- * position. */
13781378-/* The archive is assumed to be archive_size bytes long. If archive_size is 0,
13791379- * then the entire rest of the file is assumed to contain the archive. */
11681168+/* Read an archive from an already opened FILE, beginning at the current file position. */
11691169+/* The archive is assumed to be archive_size bytes long. If archive_size is 0, then the entire rest of the file is
11701170+ * assumed to contain the archive. */
13801171/* The FILE will NOT be closed when mz_zip_reader_end() is called. */
13811172MINIZ_EXPORT mz_bool mz_zip_reader_init_cfile(mz_zip_archive* pZip, MZ_FILE* pFile, mz_uint64 archive_size,
13821173 mz_uint flags);
13831174#endif
1384117513851385-/* Ends archive reading, freeing all allocations, and closing the input archive
13861386- * file if mz_zip_reader_init_file() was used. */
11761176+/* Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was
11771177+ * used. */
13871178MINIZ_EXPORT mz_bool mz_zip_reader_end(mz_zip_archive* pZip);
1388117913891180/* -------- ZIP reading or writing */
1390118113911182/* Clears a mz_zip_archive struct to all zeros. */
13921392-/* Important: This must be done before passing the struct to any mz_zip
13931393- * functions. */
11831183+/* Important: This must be done before passing the struct to any mz_zip functions. */
13941184MINIZ_EXPORT void mz_zip_zero_struct(mz_zip_archive* pZip);
1395118513961186MINIZ_EXPORT mz_zip_mode mz_zip_get_mode(mz_zip_archive* pZip);
···14031193MINIZ_EXPORT mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive* pZip);
14041194MINIZ_EXPORT MZ_FILE* mz_zip_get_cfile(mz_zip_archive* pZip);
1405119514061406-/* Reads n bytes of raw archive data, starting at file offset file_ofs, to pBuf.
14071407- */
11961196+/* Reads n bytes of raw archive data, starting at file offset file_ofs, to pBuf. */
14081197MINIZ_EXPORT size_t mz_zip_read_archive_data(mz_zip_archive* pZip, mz_uint64 file_ofs, void* pBuf, size_t n);
1409119814101410-/* All mz_zip funcs set the m_last_error field in the mz_zip_archive struct.
14111411- * These functions retrieve/manipulate this field. */
11991199+/* All mz_zip funcs set the m_last_error field in the mz_zip_archive struct. These functions retrieve/manipulate this
12001200+ * field. */
14121201/* Note that the m_last_error functionality is not thread safe. */
14131202MINIZ_EXPORT mz_zip_error mz_zip_set_last_error(mz_zip_archive* pZip, mz_zip_error err_num);
14141203MINIZ_EXPORT mz_zip_error mz_zip_peek_last_error(mz_zip_archive* pZip);
···14221211/* MZ_TRUE if the file is encrypted/strong encrypted. */
14231212MINIZ_EXPORT mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive* pZip, mz_uint file_index);
1424121314251425-/* MZ_TRUE if the compression method is supported, and the file is not
14261426- * encrypted, and the file is not a compressed patch file. */
12141214+/* MZ_TRUE if the compression method is supported, and the file is not encrypted, and the file is not a compressed patch
12151215+ * file. */
14271216MINIZ_EXPORT mz_bool mz_zip_reader_is_file_supported(mz_zip_archive* pZip, mz_uint file_index);
1428121714291218/* Retrieves the filename of an archive file entry. */
14301430-/* Returns the number of bytes written to pFilename, or if filename_buf_size is
14311431- * 0 this function returns the number of bytes needed to fully store the
14321432- * filename. */
12191219+/* Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of
12201220+ * bytes needed to fully store the filename. */
14331221MINIZ_EXPORT mz_uint mz_zip_reader_get_filename(mz_zip_archive* pZip, mz_uint file_index, char* pFilename,
14341222 mz_uint filename_buf_size);
14351223···14451233MINIZ_EXPORT mz_bool mz_zip_reader_file_stat(mz_zip_archive* pZip, mz_uint file_index, mz_zip_archive_file_stat* pStat);
1446123414471235/* MZ_TRUE if the file is in zip64 format. */
14481448-/* A file is considered zip64 if it contained a zip64 end of central directory
14491449- * marker, or if it contained any zip64 extended file information fields in the
14501450- * central directory. */
12361236+/* A file is considered zip64 if it contained a zip64 end of central directory marker, or if it contained any zip64
12371237+ * extended file information fields in the central directory. */
14511238MINIZ_EXPORT mz_bool mz_zip_is_zip64(mz_zip_archive* pZip);
1452123914531240/* Returns the total central directory size in bytes. */
···14551242MINIZ_EXPORT size_t mz_zip_get_central_dir_size(mz_zip_archive* pZip);
1456124314571244/* Extracts a archive file to a memory buffer using no memory allocation. */
14581458-/* There must be at least enough room on the stack to store the inflator's state
14591459- * (~34KB or so). */
12451245+/* There must be at least enough room on the stack to store the inflator's state (~34KB or so). */
14601246MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive* pZip, mz_uint file_index, void* pBuf,
14611247 size_t buf_size, mz_uint flags, void* pUser_read_buf,
14621248 size_t user_read_buf_size);
···14711257 size_t buf_size, mz_uint flags);
1472125814731259/* Extracts a archive file to a dynamically allocated heap buffer. */
14741474-/* The memory will be allocated via the mz_zip_archive's alloc/realloc
14751475- * functions. */
12601260+/* The memory will be allocated via the mz_zip_archive's alloc/realloc functions. */
14761261/* Returns NULL and sets the last error on failure. */
14771262MINIZ_EXPORT void* mz_zip_reader_extract_to_heap(mz_zip_archive* pZip, mz_uint file_index, size_t* pSize,
14781263 mz_uint flags);
14791264MINIZ_EXPORT void* mz_zip_reader_extract_file_to_heap(mz_zip_archive* pZip, const char* pFilename, size_t* pSize,
14801265 mz_uint flags);
1481126614821482-/* Extracts a archive file using a callback function to output the file's data.
14831483- */
12671267+/* Extracts a archive file using a callback function to output the file's data. */
14841268MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive* pZip, mz_uint file_index,
14851269 mz_file_write_func pCallback, void* pOpaque, mz_uint flags);
14861270MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive* pZip, const char* pFilename,
···14971281MINIZ_EXPORT mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state* pState);
1498128214991283#ifndef MINIZ_NO_STDIO
15001500-/* Extracts a archive file to a disk file and sets its last accessed and
15011501- * modified times. */
12841284+/* Extracts a archive file to a disk file and sets its last accessed and modified times. */
15021285/* This function only extracts files, not archive directory records. */
15031286MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_file(mz_zip_archive* pZip, mz_uint file_index, const char* pDst_filename,
15041287 mz_uint flags);
15051288MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive* pZip, const char* pArchive_filename,
15061289 const char* pDst_filename, mz_uint flags);
1507129015081508-/* Extracts a archive file starting at the current position in the destination
15091509- * FILE stream. */
12911291+/* Extracts a archive file starting at the current position in the destination FILE stream. */
15101292MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive* pZip, mz_uint file_index, MZ_FILE* File,
15111293 mz_uint flags);
15121294MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive* pZip, const char* pArchive_filename,
···15171299/* TODO */
15181300 typedef void *mz_zip_streaming_extract_state_ptr;
15191301 mz_zip_streaming_extract_state_ptr mz_zip_streaming_extract_begin(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
15201520- mz_uint64 mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
15211521- mz_uint64 mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
15221522- mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, mz_uint64 new_ofs);
13021302+ uint64_t mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
13031303+ uint64_t mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
13041304+ mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, uint64_t new_ofs);
15231305 size_t mz_zip_streaming_extract_read(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, void *pBuf, size_t buf_size);
15241306 mz_bool mz_zip_streaming_extract_end(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
15251307#endif
1526130815271527-/* This function compares the archive's local headers, the optional local zip64
15281528- * extended information block, and the optional descriptor following the
15291529- * compressed data vs. the data in the central directory. */
15301530-/* It also validates that each file can be successfully uncompressed unless the
15311531- * MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY is specified. */
13091309+/* This function compares the archive's local headers, the optional local zip64 extended information block, and the
13101310+ * optional descriptor following the compressed data vs. the data in the central directory. */
13111311+/* It also validates that each file can be successfully uncompressed unless the MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY is
13121312+ * specified. */
15321313MINIZ_EXPORT mz_bool mz_zip_validate_file(mz_zip_archive* pZip, mz_uint file_index, mz_uint flags);
1533131415341534-/* Validates an entire archive by calling mz_zip_validate_file() on each file.
15351535- */
13151315+/* Validates an entire archive by calling mz_zip_validate_file() on each file. */
15361316MINIZ_EXPORT mz_bool mz_zip_validate_archive(mz_zip_archive* pZip, mz_uint flags);
1537131715381318/* Misc utils/helpers, valid for ZIP reading or writing */
15391319MINIZ_EXPORT mz_bool mz_zip_validate_mem_archive(const void* pMem, size_t size, mz_uint flags, mz_zip_error* pErr);
15401540-#ifndef MINIZ_NO_STDIO
15411320MINIZ_EXPORT mz_bool mz_zip_validate_file_archive(const char* pFilename, mz_uint flags, mz_zip_error* pErr);
15421542-#endif
1543132115441544-/* Universal end function - calls either mz_zip_reader_end() or
15451545- * mz_zip_writer_end(). */
13221322+/* Universal end function - calls either mz_zip_reader_end() or mz_zip_writer_end(). */
15461323MINIZ_EXPORT mz_bool mz_zip_end(mz_zip_archive* pZip);
1547132415481325/* -------- ZIP writing */
···15501327#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
1551132815521329/* Inits a ZIP archive writer. */
15531553-/*Set pZip->m_pWrite (and pZip->m_pIO_opaque) before calling mz_zip_writer_init
15541554- * or mz_zip_writer_init_v2*/
15551555-/*The output is streamable, i.e. file_ofs in mz_file_write_func always increases
15561556- * only by n*/
13301330+/*Set pZip->m_pWrite (and pZip->m_pIO_opaque) before calling mz_zip_writer_init or mz_zip_writer_init_v2*/
13311331+/*The output is streamable, i.e. file_ofs in mz_file_write_func always increases only by n*/
15571332MINIZ_EXPORT mz_bool mz_zip_writer_init(mz_zip_archive* pZip, mz_uint64 existing_size);
15581333MINIZ_EXPORT mz_bool mz_zip_writer_init_v2(mz_zip_archive* pZip, mz_uint64 existing_size, mz_uint flags);
15591334···15631338 size_t initial_allocation_size, mz_uint flags);
1564133915651340#ifndef MINIZ_NO_STDIO
15661566-MINIZ_EXPORT
15671567-mz_bool mz_zip_writer_init_file(mz_zip_archive* pZip, const char* pFilename, mz_uint64 size_to_reserve_at_beginning);
13411341+MINIZ_EXPORT mz_bool mz_zip_writer_init_file(mz_zip_archive* pZip, const char* pFilename,
13421342+ mz_uint64 size_to_reserve_at_beginning);
15681343MINIZ_EXPORT mz_bool mz_zip_writer_init_file_v2(mz_zip_archive* pZip, const char* pFilename,
15691344 mz_uint64 size_to_reserve_at_beginning, mz_uint flags);
15701345MINIZ_EXPORT mz_bool mz_zip_writer_init_cfile(mz_zip_archive* pZip, MZ_FILE* pFile, mz_uint flags);
15711346#endif
1572134715731573-/* Converts a ZIP archive reader object into a writer object, to allow efficient
15741574- * in-place file appends to occur on an existing archive. */
15751575-/* For archives opened using mz_zip_reader_init_file, pFilename must be the
15761576- * archive's filename so it can be reopened for writing. If the file can't be
15771577- * reopened, mz_zip_reader_end() will be called. */
15781578-/* For archives opened using mz_zip_reader_init_mem, the memory block must be
15791579- * growable using the realloc callback (which defaults to realloc unless you've
15801580- * overridden it). */
15811581-/* Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's
15821582- * user provided m_pWrite function cannot be NULL. */
15831583-/* Note: In-place archive modification is not recommended unless you know what
15841584- * you're doing, because if execution stops or something goes wrong before */
13481348+/* Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an
13491349+ * existing archive. */
13501350+/* For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for
13511351+ * writing. If the file can't be reopened, mz_zip_reader_end() will be called. */
13521352+/* For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which
13531353+ * defaults to realloc unless you've overridden it). */
13541354+/* Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be
13551355+ * NULL. */
13561356+/* Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops
13571357+ * or something goes wrong before */
15851358/* the archive is finalized the file's central directory will be hosed. */
15861359MINIZ_EXPORT mz_bool mz_zip_writer_init_from_reader(mz_zip_archive* pZip, const char* pFilename);
15871360MINIZ_EXPORT mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive* pZip, const char* pFilename, mz_uint flags);
1588136115891589-/* Adds the contents of a memory buffer to an archive. These functions record
15901590- * the current local time into the archive. */
15911591-/* To add a directory entry, call this method with an archive name ending in a
15921592- * forwardslash with an empty buffer. */
15931593-/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED,
15941594- * MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or
15951595- * just set to MZ_DEFAULT_COMPRESSION. */
13621362+/* Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive.
13631363+ */
13641364+/* To add a directory entry, call this method with an archive name ending in a forwardslash with an empty buffer. */
13651365+/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or
13661366+ * more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
15961367MINIZ_EXPORT mz_bool mz_zip_writer_add_mem(mz_zip_archive* pZip, const char* pArchive_name, const void* pBuf,
15971368 size_t buf_size, mz_uint level_and_flags);
1598136915991599-/* Like mz_zip_writer_add_mem(), except you can specify a file comment field,
16001600- * and optionally supply the function with already compressed data. */
16011601-/* uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA
16021602- * flag is specified. */
13701370+/* Like mz_zip_writer_add_mem(), except you can specify a file comment field, and optionally supply the function with
13711371+ * already compressed data. */
13721372+/* uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA flag is specified. */
16031373MINIZ_EXPORT mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive* pZip, const char* pArchive_name, const void* pBuf,
16041374 size_t buf_size, const void* pComment, mz_uint16 comment_size,
16051375 mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
···16111381 mz_uint user_extra_data_local_len, const char* user_extra_data_central,
16121382 mz_uint user_extra_data_central_len);
1613138316141614-/* Adds the contents of a file to an archive. This function also records the
16151615- * disk file's modified time into the archive. */
16161616-/* File data is supplied via a read callback function. User
16171617- * mz_zip_writer_add_(c)file to add a file directly.*/
13841384+/* Adds the contents of a file to an archive. This function also records the disk file's modified time into the archive.
13851385+ */
13861386+/* File data is supplied via a read callback function. User mz_zip_writer_add_(c)file to add a file directly.*/
16181387MINIZ_EXPORT mz_bool mz_zip_writer_add_read_buf_callback(
16191388 mz_zip_archive* pZip, const char* pArchive_name, mz_file_read_func read_callback, void* callback_opaque,
16201389 mz_uint64 max_size, const MZ_TIME_T* pFile_time, const void* pComment, mz_uint16 comment_size,
···16221391 const char* user_extra_data_central, mz_uint user_extra_data_central_len);
1623139216241393#ifndef MINIZ_NO_STDIO
16251625-/* Adds the contents of a disk file to an archive. This function also records
16261626- * the disk file's modified time into the archive. */
16271627-/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED,
16281628- * MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or
16291629- * just set to MZ_DEFAULT_COMPRESSION. */
13941394+/* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the
13951395+ * archive. */
13961396+/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or
13971397+ * more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
16301398MINIZ_EXPORT mz_bool mz_zip_writer_add_file(mz_zip_archive* pZip, const char* pArchive_name, const char* pSrc_filename,
16311399 const void* pComment, mz_uint16 comment_size, mz_uint level_and_flags);
1632140016331633-/* Like mz_zip_writer_add_file(), except the file data is read from the
16341634- * specified FILE stream. */
14011401+/* Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream. */
16351402MINIZ_EXPORT mz_bool mz_zip_writer_add_cfile(mz_zip_archive* pZip, const char* pArchive_name, MZ_FILE* pSrc_file,
16361403 mz_uint64 max_size, const MZ_TIME_T* pFile_time, const void* pComment,
16371404 mz_uint16 comment_size, mz_uint level_and_flags,
···16401407#endif
1641140816421409/* Adds a file to an archive by fully cloning the data from another archive. */
16431643-/* This function fully clones the source file's compressed data (no
16441644- * recompression), along with its full filename, extra data (it may add or
16451645- * modify the zip64 local header extra data field), and the optional descriptor
16461646- * following the compressed data. */
14101410+/* This function fully clones the source file's compressed data (no recompression), along with its full filename, extra
14111411+ * data (it may add or modify the zip64 local header extra data field), and the optional descriptor following the
14121412+ * compressed data. */
16471413MINIZ_EXPORT mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive* pZip, mz_zip_archive* pSource_zip,
16481414 mz_uint src_file_index);
1649141516501650-/* Finalizes the archive by writing the central directory records followed by
16511651- * the end of central directory record. */
16521652-/* After an archive is finalized, the only valid call on the mz_zip_archive
16531653- * struct is mz_zip_writer_end(). */
16541654-/* An archive must be manually finalized by calling this function for it to be
16551655- * valid. */
14161416+/* Finalizes the archive by writing the central directory records followed by the end of central directory record. */
14171417+/* After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end(). */
14181418+/* An archive must be manually finalized by calling this function for it to be valid. */
16561419MINIZ_EXPORT mz_bool mz_zip_writer_finalize_archive(mz_zip_archive* pZip);
1657142016581658-/* Finalizes a heap archive, returning a pointer to the heap block and its size.
16591659- */
16601660-/* The heap block will be allocated using the mz_zip_archive's alloc/realloc
16611661- * callbacks. */
14211421+/* Finalizes a heap archive, returning a poiner to the heap block and its size. */
14221422+/* The heap block will be allocated using the mz_zip_archive's alloc/realloc callbacks. */
16621423MINIZ_EXPORT mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive* pZip, void** ppBuf, size_t* pSize);
1663142416641664-/* Ends archive writing, freeing all allocations, and closing the output file if
16651665- * mz_zip_writer_init_file() was used. */
16661666-/* Note for the archive to be valid, it *must* have been finalized before ending
16671667- * (this function will not do it for you). */
14251425+/* Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used. */
14261426+/* Note for the archive to be valid, it *must* have been finalized before ending (this function will not do it for you).
14271427+ */
16681428MINIZ_EXPORT mz_bool mz_zip_writer_end(mz_zip_archive* pZip);
1669142916701430/* -------- Misc. high-level helper functions: */
1671143116721672-/* mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically)
16731673- * appends a memory blob to a ZIP archive. */
16741674-/* Note this is NOT a fully safe operation. If it crashes or dies in some way
16751675- * your archive can be left in a screwed up state (without a central directory).
16761676- */
16771677-/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED,
16781678- * MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or
16791679- * just set to MZ_DEFAULT_COMPRESSION. */
16801680-/* TODO: Perhaps add an option to leave the existing central dir in place in
16811681- * case the add dies? We could then truncate the file (so the old central dir
16821682- * would be at the end) if something goes wrong. */
14321432+/* mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive. */
14331433+/* Note this is NOT a fully safe operation. If it crashes or dies in some way your archive can be left in a screwed up
14341434+ * state (without a central directory). */
14351435+/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or
14361436+ * more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
14371437+/* TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate
14381438+ * the file (so the old central dir would be at the end) if something goes wrong. */
16831439MINIZ_EXPORT mz_bool mz_zip_add_mem_to_archive_file_in_place(const char* pZip_filename, const char* pArchive_name,
16841440 const void* pBuf, size_t buf_size, const void* pComment,
16851441 mz_uint16 comment_size, mz_uint level_and_flags);
···16881444 mz_uint16 comment_size, mz_uint level_and_flags,
16891445 mz_zip_error* pErr);
1690144616911691-#ifndef MINIZ_NO_STDIO
16921447/* Reads a single file from an archive into a heap block. */
16931693-/* If pComment is not NULL, only the file with the specified comment will be
16941694- * extracted. */
14481448+/* If pComment is not NULL, only the file with the specified comment will be extracted. */
16951449/* Returns NULL on failure. */
16961450MINIZ_EXPORT void* mz_zip_extract_archive_file_to_heap(const char* pZip_filename, const char* pArchive_name,
16971451 size_t* pSize, mz_uint flags);
16981452MINIZ_EXPORT void* mz_zip_extract_archive_file_to_heap_v2(const char* pZip_filename, const char* pArchive_name,
16991453 const char* pComment, size_t* pSize, mz_uint flags,
17001454 mz_zip_error* pErr);
17011701-#endif
1702145517031456#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */
17041457