1 /* zip.h -- IO on .zip files using zlib
2 Version 1.2.0, September 16th, 2017
3 part of the MiniZip project
5 Copyright (C) 2012-2017 Nathan Moinvaziri
6 https://github.com/nmoinvaz/minizip
7 Copyright (C) 2009-2010 Mathias Svensson
8 Modifications for Zip64 support
10 Copyright (C) 1998-2010 Gilles Vollant
11 http://www.winimage.com/zLibDll/minizip.html
13 This program is distributed under the terms of the same license as zlib.
14 See the accompanying LICENSE file for the full text of the license.
40 #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
41 /* like the STRICT of WIN32, we define a pointer that cannot be converted
42 from (void*) without cast */
43 typedef struct TagzipFile__ { int unused; } zip_file__;
44 typedef zip_file__ *zipFile;
46 typedef voidp zipFile;
51 #define ZIP_ERRNO (Z_ERRNO)
52 #define ZIP_PARAMERROR (-102)
53 #define ZIP_BADZIPFILE (-103)
54 #define ZIP_INTERNALERROR (-104)
57 # if MAX_MEM_LEVEL >= 8
58 # define DEF_MEM_LEVEL 8
60 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
67 uint16_t internal_fa; /* internal file attributes 2 bytes */
68 uint32_t external_fa; /* external file attributes 4 bytes */
71 #define APPEND_STATUS_CREATE (0)
72 #define APPEND_STATUS_CREATEAFTER (1)
73 #define APPEND_STATUS_ADDINZIP (2)
75 /***************************************************************************/
76 /* Writing a zip file */
78 extern zipFile ZEXPORT zipOpen(const char *path, int append);
79 extern zipFile ZEXPORT zipOpen64(const void *path, int append);
82 path should contain the full path (by example, on a Windows XP computer
83 "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip".
85 return NULL if zipfile cannot be opened
86 return zipFile handle if no error
88 If the file path exist and append == APPEND_STATUS_CREATEAFTER, the zip
89 will be created at the end of the file. (useful if the file contain a self extractor code)
90 If the file path exist and append == APPEND_STATUS_ADDINZIP, we will add files in existing
91 zip (be sure you don't add file that doesn't exist)
93 NOTE: There is no delete function into a zipfile. If you want delete file into a zipfile,
94 you must open a zipfile, and create another. Of course, you can use RAW reading and writing to copy
95 the file you did not want delete. */
97 extern zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment,
98 zlib_filefunc_def *pzlib_filefunc_def);
100 extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment,
101 zlib_filefunc64_def *pzlib_filefunc_def);
103 extern zipFile ZEXPORT zipOpen3(const char *path, int append, uint64_t disk_size,
104 const char **globalcomment, zlib_filefunc_def *pzlib_filefunc_def);
105 /* Same as zipOpen2 but allows specification of spanned zip size */
107 extern zipFile ZEXPORT zipOpen3_64(const void *path, int append, uint64_t disk_size,
108 const char **globalcomment, zlib_filefunc64_def *pzlib_filefunc_def);
110 extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi,
111 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
112 uint16_t size_extrafield_global, const char *comment, uint16_t method, int level);
113 /* Open a file in the ZIP for writing.
115 filename : the filename in zip (if NULL, '-' without quote will be used
116 *zipfi contain supplemental information
117 extrafield_local buffer to store the local header extra field data, can be NULL
118 size_extrafield_local size of extrafield_local buffer
119 extrafield_global buffer to store the global header extra field data, can be NULL
120 size_extrafield_global size of extrafield_local buffer
121 comment buffer for comment string
122 method contain the compression method (0 for store, Z_DEFLATED for deflate)
123 level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
124 zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
125 this MUST be '1' if the uncompressed size is >= 0xffffffff. */
127 extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
128 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
129 uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int zip64);
130 /* Same as zipOpenNewFileInZip with zip64 support */
132 extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi,
133 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
134 uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw);
135 /* Same as zipOpenNewFileInZip, except if raw=1, we write raw file */
137 extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
138 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
139 uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int zip64);
140 /* Same as zipOpenNewFileInZip3 with zip64 support */
142 extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
143 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
144 uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
145 int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting);
146 /* Same as zipOpenNewFileInZip2, except
147 windowBits, memLevel, strategy : see parameter strategy in deflateInit2
148 password : crypting password (NULL for no crypting)
149 crc_for_crypting : crc of file to compress (needed for crypting) */
151 extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
152 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
153 uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
154 int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, int zip64);
155 /* Same as zipOpenNewFileInZip3 with zip64 support */
157 extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
158 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
159 uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
160 int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base);
161 /* Same as zipOpenNewFileInZip3 except versionMadeBy & flag fields */
163 extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
164 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
165 uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
166 int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
167 /* Same as zipOpenNewFileInZip4 with zip64 support */
169 extern int ZEXPORT zipOpenNewFileInZip5(zipFile file,
170 const char *filename,
171 const zip_fileinfo *zipfi,
172 const void *extrafield_local,
173 uint16_t size_extrafield_local,
174 const void *extrafield_global,
175 uint16_t size_extrafield_global,
185 const char *password,
187 /* Allowing optional aes */
189 extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len);
190 /* Write data in the zipfile */
192 extern int ZEXPORT zipCloseFileInZip(zipFile file);
193 /* Close the current file in the zipfile */
195 extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32);
196 extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32);
197 /* Close the current file in the zipfile, for file opened with parameter raw=1 in zipOpenNewFileInZip2
198 where raw is compressed data. Parameters uncompressed_size and crc32 are value for the uncompressed data. */
200 extern int ZEXPORT zipClose(zipFile file, const char *global_comment);
201 /* Close the zipfile */
203 extern int ZEXPORT zipClose_64(zipFile file, const char *global_comment);
205 extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby);
206 /* Same as zipClose_64 except version_madeby field */
208 /***************************************************************************/