1 
2 #pragma once
3 #include "miniz.h"
4 
5 /* ------------------- ZIP archive reading/writing */
6 
7 #ifndef MINIZ_NO_ARCHIVE_APIS
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 enum
14 {
15     /* Note: These enums can be reduced as needed to save memory or stack space - they are pretty conservative. */
16     MZ_ZIP_MAX_IO_BUF_SIZE = 64 * 1024,
17     MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 512,
18     MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 512
19 };
20 
21 typedef struct
22 {
23     /* Central directory file index. */
24     mz_uint32 m_file_index;
25 
26     /* Byte offset of this entry in the archive's central directory. Note we currently only support up to UINT_MAX or less bytes in the central dir. */
27     mz_uint64 m_central_dir_ofs;
28 
29     /* These fields are copied directly from the zip's central dir. */
30     mz_uint16 m_version_made_by;
31     mz_uint16 m_version_needed;
32     mz_uint16 m_bit_flag;
33     mz_uint16 m_method;
34 
35 #ifndef MINIZ_NO_TIME
36     MZ_TIME_T m_time;
37 #endif
38 
39     /* CRC-32 of uncompressed data. */
40     mz_uint32 m_crc32;
41 
42     /* File's compressed size. */
43     mz_uint64 m_comp_size;
44 
45     /* File's uncompressed size. Note, I've seen some old archives where directory entries had 512 bytes for their uncompressed sizes, but when you try to unpack them you actually get 0 bytes. */
46     mz_uint64 m_uncomp_size;
47 
48     /* Zip internal and external file attributes. */
49     mz_uint16 m_internal_attr;
50     mz_uint32 m_external_attr;
51 
52     /* Entry's local header file offset in bytes. */
53     mz_uint64 m_local_header_ofs;
54 
55     /* Size of comment in bytes. */
56     mz_uint32 m_comment_size;
57 
58     /* MZ_TRUE if the entry appears to be a directory. */
59     mz_bool m_is_directory;
60 
61     /* MZ_TRUE if the entry uses encryption/strong encryption (which miniz_zip doesn't support) */
62     mz_bool m_is_encrypted;
63 
64     /* MZ_TRUE if the file is not encrypted, a patch file, and if it uses a compression method we support. */
65     mz_bool m_is_supported;
66 
67     /* Filename. If string ends in '/' it's a subdirectory entry. */
68     /* Guaranteed to be zero terminated, may be truncated to fit. */
69     char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
70 
71     /* Comment field. */
72     /* Guaranteed to be zero terminated, may be truncated to fit. */
73     char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
74 
75 } mz_zip_archive_file_stat;
76 
77 typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
78 typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
79 typedef mz_bool (*mz_file_needs_keepalive)(void *pOpaque);
80 
81 struct mz_zip_internal_state_tag;
82 typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
83 
84 typedef enum {
85     MZ_ZIP_MODE_INVALID = 0,
86     MZ_ZIP_MODE_READING = 1,
87     MZ_ZIP_MODE_WRITING = 2,
88     MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
89 } mz_zip_mode;
90 
91 typedef enum {
92     MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
93     MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
94     MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
95     MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800,
96     MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG = 0x1000, /* if enabled, mz_zip_reader_locate_file() will be called on each file as its validated to ensure the func finds the file in the central dir (intended for testing) */
97     MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000,     /* validate the local headers, but don't decompress the entire file and check the crc32 */
98     MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000,               /* always use the zip64 file format, instead of the original zip file format with automatic switch to zip64. Use as flags parameter with mz_zip_writer_init*_v2 */
99     MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000,
100     MZ_ZIP_FLAG_ASCII_FILENAME = 0x10000
101 } mz_zip_flags;
102 
103 typedef enum {
104     MZ_ZIP_TYPE_INVALID = 0,
105     MZ_ZIP_TYPE_USER,
106     MZ_ZIP_TYPE_MEMORY,
107     MZ_ZIP_TYPE_HEAP,
108     MZ_ZIP_TYPE_FILE,
109     MZ_ZIP_TYPE_CFILE,
110     MZ_ZIP_TOTAL_TYPES
111 } mz_zip_type;
112 
113 /* miniz error codes. Be sure to update mz_zip_get_error_string() if you add or modify this enum. */
114 typedef enum {
115     MZ_ZIP_NO_ERROR = 0,
116     MZ_ZIP_UNDEFINED_ERROR,
117     MZ_ZIP_TOO_MANY_FILES,
118     MZ_ZIP_FILE_TOO_LARGE,
119     MZ_ZIP_UNSUPPORTED_METHOD,
120     MZ_ZIP_UNSUPPORTED_ENCRYPTION,
121     MZ_ZIP_UNSUPPORTED_FEATURE,
122     MZ_ZIP_FAILED_FINDING_CENTRAL_DIR,
123     MZ_ZIP_NOT_AN_ARCHIVE,
124     MZ_ZIP_INVALID_HEADER_OR_CORRUPTED,
125     MZ_ZIP_UNSUPPORTED_MULTIDISK,
126     MZ_ZIP_DECOMPRESSION_FAILED,
127     MZ_ZIP_COMPRESSION_FAILED,
128     MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE,
129     MZ_ZIP_CRC_CHECK_FAILED,
130     MZ_ZIP_UNSUPPORTED_CDIR_SIZE,
131     MZ_ZIP_ALLOC_FAILED,
132     MZ_ZIP_FILE_OPEN_FAILED,
133     MZ_ZIP_FILE_CREATE_FAILED,
134     MZ_ZIP_FILE_WRITE_FAILED,
135     MZ_ZIP_FILE_READ_FAILED,
136     MZ_ZIP_FILE_CLOSE_FAILED,
137     MZ_ZIP_FILE_SEEK_FAILED,
138     MZ_ZIP_FILE_STAT_FAILED,
139     MZ_ZIP_INVALID_PARAMETER,
140     MZ_ZIP_INVALID_FILENAME,
141     MZ_ZIP_BUF_TOO_SMALL,
142     MZ_ZIP_INTERNAL_ERROR,
143     MZ_ZIP_FILE_NOT_FOUND,
144     MZ_ZIP_ARCHIVE_TOO_LARGE,
145     MZ_ZIP_VALIDATION_FAILED,
146     MZ_ZIP_WRITE_CALLBACK_FAILED,
147     MZ_ZIP_TOTAL_ERRORS
148 } mz_zip_error;
149 
150 typedef struct
151 {
152     mz_uint64 m_archive_size;
153     mz_uint64 m_central_directory_file_ofs;
154 
155     /* We only support up to UINT32_MAX files in zip64 mode. */
156     mz_uint32 m_total_files;
157     mz_zip_mode m_zip_mode;
158     mz_zip_type m_zip_type;
159     mz_zip_error m_last_error;
160 
161     mz_uint64 m_file_offset_alignment;
162 
163     mz_alloc_func m_pAlloc;
164     mz_free_func m_pFree;
165     mz_realloc_func m_pRealloc;
166     void *m_pAlloc_opaque;
167 
168     mz_file_read_func m_pRead;
169     mz_file_write_func m_pWrite;
170     mz_file_needs_keepalive m_pNeeds_keepalive;
171     void *m_pIO_opaque;
172 
173     mz_zip_internal_state *m_pState;
174 
175 } mz_zip_archive;
176 
177 typedef struct
178 {
179     mz_zip_archive *pZip;
180     mz_uint flags;
181 
182     int status;
183 #ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
184     mz_uint file_crc32;
185 #endif
186     mz_uint64 read_buf_size, read_buf_ofs, read_buf_avail, comp_remaining, out_buf_ofs, cur_file_ofs;
187     mz_zip_archive_file_stat file_stat;
188     void *pRead_buf;
189     void *pWrite_buf;
190 
191     size_t out_blk_remain;
192 
193     tinfl_decompressor inflator;
194 
195 } mz_zip_reader_extract_iter_state;
196 
197 /* -------- ZIP reading */
198 
199 /* Inits a ZIP archive reader. */
200 /* These functions read and validate the archive's central directory. */
201 mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint flags);
202 
203 mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags);
204 
205 #ifndef MINIZ_NO_STDIO
206 /* Read a archive from a disk file. */
207 /* file_start_ofs is the file offset where the archive actually begins, or 0. */
208 /* actual_archive_size is the true total size of the archive, which may be smaller than the file's actual size on disk. If zero the entire file is treated as the archive. */
209 mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
210 mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size);
211 
212 /* Read an archive from an already opened FILE, beginning at the current file position. */
213 /* The archive is assumed to be archive_size bytes long. If archive_size is < 0, then the entire rest of the file is assumed to contain the archive. */
214 /* The FILE will NOT be closed when mz_zip_reader_end() is called. */
215 mz_bool mz_zip_reader_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint64 archive_size, mz_uint flags);
216 #endif
217 
218 /* Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used. */
219 mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
220 
221 /* -------- ZIP reading or writing */
222 
223 /* Clears a mz_zip_archive struct to all zeros. */
224 /* Important: This must be done before passing the struct to any mz_zip functions. */
225 void mz_zip_zero_struct(mz_zip_archive *pZip);
226 
227 mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip);
228 mz_zip_type mz_zip_get_type(mz_zip_archive *pZip);
229 
230 /* Returns the total number of files in the archive. */
231 mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
232 
233 mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip);
234 mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip);
235 MZ_FILE *mz_zip_get_cfile(mz_zip_archive *pZip);
236 
237 /* Reads n bytes of raw archive data, starting at file offset file_ofs, to pBuf. */
238 size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n);
239 
240 /* All mz_zip funcs set the m_last_error field in the mz_zip_archive struct. These functions retrieve/manipulate this field. */
241 /* Note that the m_last_error functionality is not thread safe. */
242 mz_zip_error mz_zip_set_last_error(mz_zip_archive *pZip, mz_zip_error err_num);
243 mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip);
244 mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip);
245 mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip);
246 const char *mz_zip_get_error_string(mz_zip_error mz_err);
247 
248 /* MZ_TRUE if the archive file entry is a directory entry. */
249 mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
250 
251 /* MZ_TRUE if the file is encrypted/strong encrypted. */
252 mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
253 
254 /* MZ_TRUE if the compression method is supported, and the file is not encrypted, and the file is not a compressed patch file. */
255 mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index);
256 
257 /* Retrieves the filename of an archive file entry. */
258 /* Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename. */
259 mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
260 
261 /* Attempts to locates a file in the archive's central directory. */
262 /* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */
263 /* Returns -1 if the file cannot be found. */
264 int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
265 int mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *file_index);
266 
267 /* Returns detailed information about an archive file entry. */
268 mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
269 
270 /* MZ_TRUE if the file is in zip64 format. */
271 /* A file is considered zip64 if it contained a zip64 end of central directory marker, or if it contained any zip64 extended file information fields in the central directory. */
272 mz_bool mz_zip_is_zip64(mz_zip_archive *pZip);
273 
274 /* Returns the total central directory size in bytes. */
275 /* The current max supported size is <= MZ_UINT32_MAX. */
276 size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip);
277 
278 /* Extracts a archive file to a memory buffer using no memory allocation. */
279 /* There must be at least enough room on the stack to store the inflator's state (~34KB or so). */
280 mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
281 mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
282 
283 /* Extracts a archive file to a memory buffer. */
284 mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags);
285 mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags);
286 
287 /* Extracts a archive file to a dynamically allocated heap buffer. */
288 /* The memory will be allocated via the mz_zip_archive's alloc/realloc functions. */
289 /* Returns NULL and sets the last error on failure. */
290 void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
291 void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
292 
293 /* Extracts a archive file using a callback function to output the file's data. */
294 mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
295 mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
296 
297 /* Extract a file iteratively */
298 mz_zip_reader_extract_iter_state* mz_zip_reader_extract_iter_new(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
299 mz_zip_reader_extract_iter_state* mz_zip_reader_extract_file_iter_new(mz_zip_archive *pZip, const char *pFilename, mz_uint flags);
300 size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state* pState, void* pvBuf, size_t buf_size);
301 mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state* pState);
302 
303 #ifndef MINIZ_NO_STDIO
304 /* Extracts a archive file to a disk file and sets its last accessed and modified times. */
305 /* This function only extracts files, not archive directory records. */
306 mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
307 mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
308 
309 /* Extracts a archive file starting at the current position in the destination FILE stream. */
310 mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *File, mz_uint flags);
311 mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags);
312 #endif
313 
314 #if 0
315 /* TODO */
316 	typedef void *mz_zip_streaming_extract_state_ptr;
317 	mz_zip_streaming_extract_state_ptr mz_zip_streaming_extract_begin(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
318 	uint64_t mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
319 	uint64_t mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
320 	mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, uint64_t new_ofs);
321 	size_t mz_zip_streaming_extract_read(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, void *pBuf, size_t buf_size);
322 	mz_bool mz_zip_streaming_extract_end(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
323 #endif
324 
325 /* This function compares the archive's local headers, the optional local zip64 extended information block, and the optional descriptor following the compressed data vs. the data in the central directory. */
326 /* It also validates that each file can be successfully uncompressed unless the MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY is specified. */
327 mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
328 
329 /* Validates an entire archive by calling mz_zip_validate_file() on each file. */
330 mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags);
331 
332 /* Misc utils/helpers, valid for ZIP reading or writing */
333 mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr);
334 mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr);
335 
336 /* Universal end function - calls either mz_zip_reader_end() or mz_zip_writer_end(). */
337 mz_bool mz_zip_end(mz_zip_archive *pZip);
338 
339 /* -------- ZIP writing */
340 
341 #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
342 
343 /* Inits a ZIP archive writer. */
344 /*Set pZip->m_pWrite (and pZip->m_pIO_opaque) before calling mz_zip_writer_init or mz_zip_writer_init_v2*/
345 /*The output is streamable, i.e. file_ofs in mz_file_write_func always increases only by n*/
346 mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
347 mz_bool mz_zip_writer_init_v2(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags);
348 
349 mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
350 mz_bool mz_zip_writer_init_heap_v2(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags);
351 
352 #ifndef MINIZ_NO_STDIO
353 mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
354 mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags);
355 mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags);
356 #endif
357 
358 /* Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive. */
359 /* For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for writing. If the file can't be reopened, mz_zip_reader_end() will be called. */
360 /* For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which defaults to realloc unless you've overridden it). */
361 /* Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL. */
362 /* Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before */
363 /* the archive is finalized the file's central directory will be hosed. */
364 mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
365 mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags);
366 
367 /* Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive. */
368 /* To add a directory entry, call this method with an archive name ending in a forwardslash with an empty buffer. */
369 /* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
370 mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags);
371 
372 /* Like mz_zip_writer_add_mem(), except you can specify a file comment field, and optionally supply the function with already compressed data. */
373 /* uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA flag is specified. */
374 mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
375                                  mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
376 
377 mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
378                                     mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
379                                     const char *user_extra_data_central, mz_uint user_extra_data_central_len);
380 
381 #ifndef MINIZ_NO_STDIO
382 /* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */
383 /* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
384 mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
385 
386 /* Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream. */
387 mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add,
388                                 const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
389                                 const char *user_extra_data_central, mz_uint user_extra_data_central_len);
390 #endif
391 
392 /* Adds a file to an archive by fully cloning the data from another archive. */
393 /* This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data (it may add or modify the zip64 local header extra data field), and the optional descriptor following the compressed data. */
394 mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index);
395 
396 /* Finalizes the archive by writing the central directory records followed by the end of central directory record. */
397 /* After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end(). */
398 /* An archive must be manually finalized by calling this function for it to be valid. */
399 mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
400 
401 /* Finalizes a heap archive, returning a poiner to the heap block and its size. */
402 /* The heap block will be allocated using the mz_zip_archive's alloc/realloc callbacks. */
403 mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **ppBuf, size_t *pSize);
404 
405 /* Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used. */
406 /* Note for the archive to be valid, it *must* have been finalized before ending (this function will not do it for you). */
407 mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
408 
409 /* -------- Misc. high-level helper functions: */
410 
411 /* mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive. */
412 /* Note this is NOT a fully safe operation. If it crashes or dies in some way your archive can be left in a screwed up state (without a central directory). */
413 /* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
414 /* TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate the file (so the old central dir would be at the end) if something goes wrong. */
415 mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
416 mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr);
417 
418 /* Reads a single file from an archive into a heap block. */
419 /* If pComment is not NULL, only the file with the specified comment will be extracted. */
420 /* Returns NULL on failure. */
421 void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags);
422 void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr);
423 
424 #endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */
425 
426 #ifdef __cplusplus
427 }
428 #endif
429 
430 #endif /* MINIZ_NO_ARCHIVE_APIS */
431