]> git.cworth.org Git - vogl/blob - src/voglcore/vogl_miniz_zip.h
Initial vogl checkin
[vogl] / src / voglcore / vogl_miniz_zip.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 // File: vogl_miniz_zip.h
28 #ifndef VOGL_MINIZ_ZIP_H
29 #define VOGL_MINIZ_ZIP_H
30
31 #include "vogl_miniz.h"
32
33 // ------------------- ZIP archive reading/writing
34
35 //#define MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #ifndef MINIZ_NO_ARCHIVE_APIS
42
43 enum
44 {
45     // Note: These enums can be reduced as needed to save memory or stack space - they are pretty conservative.
46     MZ_ZIP_MAX_IO_BUF_SIZE = 64 * 1024,
47     MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 512,
48     MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 512
49 };
50
51 typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
52 typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
53
54 struct mz_zip_internal_state_tag;
55 typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
56
57 typedef enum
58 {
59     MZ_ZIP_MODE_INVALID = 0,
60     MZ_ZIP_MODE_READING = 1,
61     MZ_ZIP_MODE_WRITING = 2,
62     MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
63 } mz_zip_mode;
64
65 typedef enum
66 {
67     MZ_ZIP_TYPE_INVALID = 0,
68     MZ_ZIP_TYPE_USER,
69     MZ_ZIP_TYPE_MEMORY,
70     MZ_ZIP_TYPE_HEAP,
71     MZ_ZIP_TYPE_FILE,
72     MZ_ZIP_TYPE_CFILE,
73     MZ_ZIP_TOTAL_TYPES
74 } mz_zip_type;
75
76 // miniz error codes. Be sure to update mz_zip_get_error_string() if you add or modify this enum.
77 typedef enum
78 {
79     MZ_ZIP_NO_ERROR = 0,
80     MZ_ZIP_UNDEFINED_ERROR,
81     MZ_ZIP_TOO_MANY_FILES,
82     MZ_ZIP_FILE_TOO_LARGE,
83     MZ_ZIP_UNSUPPORTED_METHOD,
84     MZ_ZIP_UNSUPPORTED_ENCRYPTION,
85     MZ_ZIP_UNSUPPORTED_FEATURE,
86     MZ_ZIP_FAILED_FINDING_CENTRAL_DIR,
87     MZ_ZIP_NOT_AN_ARCHIVE,
88     MZ_ZIP_INVALID_HEADER_OR_CORRUPTED,
89     MZ_ZIP_UNSUPPORTED_MULTIDISK,
90     MZ_ZIP_DECOMPRESSION_FAILED,
91     MZ_ZIP_COMPRESSION_FAILED,
92     MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE,
93     MZ_ZIP_CRC_CHECK_FAILED,
94     MZ_ZIP_UNSUPPORTED_CDIR_SIZE,
95     MZ_ZIP_ALLOC_FAILED,
96     MZ_ZIP_FILE_OPEN_FAILED,
97     MZ_ZIP_FILE_CREATE_FAILED,
98     MZ_ZIP_FILE_WRITE_FAILED,
99     MZ_ZIP_FILE_READ_FAILED,
100     MZ_ZIP_FILE_CLOSE_FAILED,
101     MZ_ZIP_FILE_SEEK_FAILED,
102     MZ_ZIP_FILE_STAT_FAILED,
103     MZ_ZIP_INVALID_PARAMETER,
104     MZ_ZIP_INVALID_FILENAME,
105     MZ_ZIP_BUF_TOO_SMALL,
106     MZ_ZIP_INTERNAL_ERROR,
107     MZ_ZIP_FILE_NOT_FOUND,
108     MZ_ZIP_ARCHIVE_TOO_LARGE,
109     MZ_ZIP_VALIDATION_FAILED,
110     MZ_ZIP_WRITE_CALLBACK_FAILED,
111     MZ_ZIP_TOTAL_ERRORS
112 } mz_zip_error;
113
114 typedef struct
115 {
116     mz_uint64 m_archive_size;
117     mz_uint64 m_central_directory_file_ofs;
118
119     // We only support up to UINT32_MAX files in zip64 mode.
120     mz_uint32 m_total_files;
121     mz_zip_mode m_zip_mode;
122     mz_zip_type m_zip_type;
123     mz_zip_error m_last_error;
124
125     mz_uint64 m_file_offset_alignment;
126
127     mz_alloc_func m_pAlloc;
128     mz_free_func m_pFree;
129     mz_realloc_func m_pRealloc;
130     void *m_pAlloc_opaque;
131
132     mz_file_read_func m_pRead;
133     mz_file_write_func m_pWrite;
134     void *m_pIO_opaque;
135
136     mz_zip_internal_state *m_pState;
137
138 } mz_zip_archive;
139
140 typedef enum
141 {
142     MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
143     MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
144     MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
145     MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800,
146     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)
147     MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000,     // validate the local headers, but don't decompress the entire file and check the crc32
148     MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000,               // use the zip64 file format, instead of the original zip file format
149     MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000
150 } mz_zip_flags;
151
152 #ifdef MINIZ_NO_STDIO
153 #define MZ_FILE void *
154 #else
155 #include <stdio.h>
156 #define MZ_FILE FILE
157 #endif // #ifdef MINIZ_NO_STDIO
158
159 #ifdef MINIZ_NO_TIME
160 typedef struct mz_dummy_time_t_tag
161 {
162     int m_dummy;
163 } mz_dummy_time_t;
164 #define MZ_TIME_T mz_dummy_time_t
165 #else
166 #define MZ_TIME_T time_t
167 #endif
168
169 typedef struct
170 {
171     // Central directory file index.
172     mz_uint32 m_file_index;
173
174     // 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.
175     mz_uint64 m_central_dir_ofs;
176
177     // These fields are copied directly from the zip's central dir.
178     mz_uint16 m_version_made_by;
179     mz_uint16 m_version_needed;
180     mz_uint16 m_bit_flag;
181     mz_uint16 m_method;
182
183 #ifndef MINIZ_NO_TIME
184     MZ_TIME_T m_time;
185 #endif
186
187     // CRC-32 of uncompressed data.
188     mz_uint32 m_crc32;
189
190     // File's compressed size.
191     mz_uint64 m_comp_size;
192
193     // 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.
194     mz_uint64 m_uncomp_size;
195
196     // Zip internal and external file attributes.
197     mz_uint16 m_internal_attr;
198     mz_uint32 m_external_attr;
199
200     // Entry's local header file offset in bytes.
201     mz_uint64 m_local_header_ofs;
202
203     // Size of comment in bytes.
204     mz_uint32 m_comment_size;
205
206     // MZ_TRUE if the entry appears to be a directory.
207     mz_bool m_is_directory;
208
209     // MZ_TRUE if the entry uses encryption/strong encryption (which miniz_zip doesn't support)
210     mz_bool m_is_encrypted;
211
212     // MZ_TRUE if the file is not encrypted, a patch file, and if it uses a compression method we support.
213     mz_bool m_is_supported;
214
215     // Filename. If string ends in '/' it's a subdirectory entry.
216     // Guaranteed to be zero terminated, may be truncated to fit.
217     char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
218
219     // Comment field.
220     // Guaranteed to be zero terminated, may be truncated to fit.
221     char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
222
223 } mz_zip_archive_file_stat;
224
225 // -------- ZIP reading
226
227 // Inits a ZIP archive reader.
228 // These functions read and validate the archive's central directory.
229 mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint flags);
230
231 mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags);
232
233 #ifndef MINIZ_NO_STDIO
234 // Read a archive from a disk file.
235 // file_start_ofs is the file offset where the archive actually begins, or 0.
236 // 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.
237 mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size);
238
239 // Read an archive from an already opened FILE, beginning at the current file position.
240 // 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.
241 // The FILE will NOT be closed when mz_zip_reader_end() is called.
242 mz_bool mz_zip_reader_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint64 archive_size, mz_uint flags);
243 #endif
244
245 // Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used.
246 mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
247
248 // -------- ZIP reading or writing
249
250 // Clears a mz_zip_archive struct to all zeros.
251 // Important: This must be done before passing the struct to any mz_zip functions.
252 void mz_zip_zero_struct(mz_zip_archive *pZip);
253
254 mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip);
255 mz_zip_type mz_zip_get_type(mz_zip_archive *pZip);
256
257 // Returns the total number of files in the archive.
258 mz_uint mz_zip_get_num_files(mz_zip_archive *pZip);
259
260 mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip);
261 mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip);
262 MZ_FILE *mz_zip_get_cfile(mz_zip_archive *pZip);
263
264 // Reads n bytes of raw archive data, starting at file offset file_ofs, to pBuf.
265 size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n);
266
267 // Attempts to locates a file in the archive's central directory.
268 // Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH
269 // Returns MZ_FALSE if the file cannot be found.
270 mz_bool mz_zip_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *pIndex);
271
272 // All mz_zip funcs set the m_last_error field in the mz_zip_archive struct. These functions retrieve/manipulate this field.
273 // Note that the m_last_error functionality is not thread safe.
274 mz_zip_error mz_zip_set_last_error(mz_zip_archive *pZip, mz_zip_error err_num);
275 mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip);
276 mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip);
277 mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip);
278 const char *mz_zip_get_error_string(mz_zip_error mz_err);
279
280 // MZ_TRUE if the archive file entry is a directory entry.
281 mz_bool mz_zip_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
282
283 // MZ_TRUE if the file is encrypted/strong encrypted.
284 mz_bool mz_zip_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
285
286 // MZ_TRUE if the compression method is supported, and the file is not encrypted, and the file is not a compressed patch file.
287 mz_bool mz_zip_is_file_supported(mz_zip_archive *pZip, mz_uint file_index);
288
289 // Retrieves the filename of an archive file entry.
290 // 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.
291 mz_uint mz_zip_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
292
293 // Returns detailed information about an archive file entry.
294 mz_bool mz_zip_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
295
296 // MZ_TRUE if the file is in zip64 format.
297 // 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.
298 mz_bool mz_zip_is_zip64(mz_zip_archive *pZip);
299
300 // Returns the total central directory size in bytes.
301 // The current max supported size is <= MZ_UINT32_MAX.
302 size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip);
303
304 // Extracts a archive file to a memory buffer using no memory allocation.
305 // There must be at least enough room on the stack to store the inflator's state (~34KB or so).
306 mz_bool mz_zip_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);
307 mz_bool mz_zip_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);
308
309 // Extracts a archive file to a memory buffer.
310 mz_bool mz_zip_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags);
311 mz_bool mz_zip_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags);
312
313 // Extracts a archive file to a dynamically allocated heap buffer.
314 // The memory will be allocated via the mz_zip_archive's alloc/realloc functions.
315 // Returns NULL and sets the last error on failure.
316 void *mz_zip_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
317 void *mz_zip_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
318
319 // Extracts a archive file using a callback function to output the file's data.
320 mz_bool mz_zip_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
321 mz_bool mz_zip_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
322
323 #ifndef MINIZ_NO_STDIO
324 // Extracts a archive file to a disk file and sets its last accessed and modified times.
325 // This function only extracts files, not archive directory records.
326 mz_bool mz_zip_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
327 mz_bool mz_zip_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
328
329 // Extracts a archive file starting at the current position in the destination FILE stream.
330 mz_bool mz_zip_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *File, mz_uint flags);
331 mz_bool mz_zip_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags);
332 #endif
333
334 #if 0
335 // TODO
336         typedef void *mz_zip_streaming_extract_state_ptr;
337         mz_zip_streaming_extract_state_ptr mz_zip_streaming_extract_begin(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
338         uint64_t mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
339         uint64_t mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
340         mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, uint64_t new_ofs);
341         size_t mz_zip_streaming_extract_read(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, void *pBuf, size_t buf_size);
342         mz_bool mz_zip_streaming_extract_end(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
343 #endif
344
345 // 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.
346 // It also validates that each file can be successfully uncompressed unless the MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY is specified.
347 mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
348
349 // Validates an entire archive by calling mz_zip_validate_file() on each file.
350 mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags);
351
352 // Misc utils/helpers, valid for ZIP reading or writing
353 mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr);
354 mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr);
355
356 // Universal end function - calls either mz_zip_reader_end() or mz_zip_writer_end().
357 mz_bool mz_zip_end(mz_zip_archive *pZip);
358
359 // -------- ZIP writing
360
361 #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
362
363 // Inits a ZIP archive writer.
364 mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags);
365 mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags);
366
367 #ifndef MINIZ_NO_STDIO
368 mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags);
369 mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags);
370 #endif
371
372 // Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive.
373 // 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.
374 // 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).
375 // Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL.
376 // Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before
377 // the archive is finalized the file's central directory will be hosed.
378 mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename, mz_uint flags);
379
380 // Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive.
381 // To add a directory entry, call this method with an archive name ending in a forwardslash with an empty buffer.
382 // 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.
383 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);
384
385 // Like mz_zip_writer_add_mem(), except you can specify a file comment field, and optionally supply the function with already compressed data.
386 // uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA flag is specified.
387 mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
388
389 #ifndef MINIZ_NO_STDIO
390 // Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive.
391 // 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.
392 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);
393
394 // Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream.
395 mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add, const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
396 #endif
397
398 // Adds a file to an archive by fully cloning the data from another archive.
399 // 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.
400 mz_bool mz_zip_writer_add_from_other_zip(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index);
401
402 // Finalizes the archive by writing the central directory records followed by the end of central directory record.
403 // After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end().
404 // An archive must be manually finalized by calling this function for it to be valid.
405 mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
406
407 // Finalizes a heap archive, returning a poiner to the heap block and its size.
408 // The heap block will be allocated using the mz_zip_archive's alloc/realloc callbacks.
409 mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **ppBuf, size_t *pSize);
410
411 // Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used.
412 // Note for the archive to be valid, it *must* have been finalized before ending (this function will not do it for you).
413 mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
414
415 // -------- Misc. high-level helper functions:
416
417 // mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive.
418 // 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).
419 // 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.
420 // 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.
421 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, mz_zip_error *pErr);
422
423 // Reads a single file from an archive into a heap block.
424 // If pComment is not NULL, only the file with the specified comment will be extracted.
425 // Returns NULL on failure.
426 void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr);
427
428 #endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
429
430 #endif // #ifndef MINIZ_NO_ARCHIVE_APIS
431
432 #ifdef __cplusplus
433 }
434 #endif
435
436 #endif // VOGL_MINIZ_ZIP_H