1 /* unzip.h -- IO for uncompress .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 on both zip and unzip
10 Copyright (C) 2007-2008 Even Rouault
11 Modifications of Unzip for Zip64
12 Copyright (C) 1998-2010 Gilles Vollant
13 http://www.winimage.com/zLibDll/minizip.html
15 This program is distributed under the terms of the same license as zlib.
16 See the accompanying LICENSE file for the full text of the license.
22 #include "SSZipCommon.h"
44 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
45 /* like the STRICT of WIN32, we define a pointer that cannot be converted
46 from (void*) without cast */
47 typedef struct TagunzFile__ { int unused; } unz_file__;
48 typedef unz_file__ *unzFile;
50 typedef voidp unzFile;
54 #define UNZ_END_OF_LIST_OF_FILE (-100)
55 #define UNZ_ERRNO (Z_ERRNO)
57 #define UNZ_PARAMERROR (-102)
58 #define UNZ_BADZIPFILE (-103)
59 #define UNZ_INTERNALERROR (-104)
60 #define UNZ_CRCERROR (-105)
61 #define UNZ_BADPASSWORD (-106)
64 /***************************************************************************/
65 /* Opening and close a zip file */
67 extern unzFile ZEXPORT unzOpen(const char *path);
68 extern unzFile ZEXPORT unzOpen64(const void *path);
71 path should contain the full path (by example, on a Windows XP computer
72 "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip".
73 return NULL if zipfile cannot be opened or doesn't exist
74 return unzFile handle if no error
76 NOTE: The "64" function take a const void *pointer, because the path is just the value passed to the
77 open64_file_func callback. Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
78 is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char *does not describe the reality */
80 extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def);
81 /* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write operations */
82 extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def);
83 /* Open a Zip file, like unz64Open, but provide a set of file low level API for read/write 64-bit operations */
85 extern int ZEXPORT unzClose(unzFile file);
86 /* Close a ZipFile opened with unzOpen. If there is files inside the .Zip opened with unzOpenCurrentFile,
87 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
89 return UNZ_OK if there is no error */
91 extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info);
92 extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info);
93 /* Write info about the ZipFile in the *pglobal_info structure.
95 return UNZ_OK if no error */
97 extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size);
98 /* Get the global comment string of the ZipFile, in the comment buffer.
100 uSizeBuf is the size of the szComment buffer.
101 return the number of byte copied or an error code <0 */
103 extern uint64_t ZEXPORT unzCountEntries(const unzFile file);
105 /***************************************************************************/
106 /* Reading the content of the current zipfile, you can open it, read data from it, and close it
107 (you can close it before reading all the file) */
109 extern int ZEXPORT unzOpenCurrentFile(unzFile file);
110 /* Open for reading data the current file in the zipfile.
112 return UNZ_OK if no error */
114 extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password);
115 /* Open for reading data the current file in the zipfile.
116 password is a crypting password
118 return UNZ_OK if no error */
120 extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw);
121 /* Same as unzOpenCurrentFile, but open for read raw the file (not uncompress)
122 if raw==1 *method will receive method of compression, *level will receive level of compression
124 NOTE: you can set level parameter as NULL (if you did not want known level,
125 but you CANNOT set method parameter as NULL */
127 extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password);
128 /* Same as unzOpenCurrentFile, but takes extra parameter password for encrypted files */
130 extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, uint32_t len);
131 /* Read bytes from the current file (opened by unzOpenCurrentFile)
132 buf contain buffer where data must be copied
135 return the number of byte copied if somes bytes are copied
136 return 0 if the end of file was reached
137 return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */
139 extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
140 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
141 extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *filename,
142 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
143 /* Get Info about the current file
145 pfile_info if != NULL, the *pfile_info structure will contain somes info about the current file
146 filename if != NULL, the file name string will be copied in filename
147 filename_size is the size of the filename buffer
148 extrafield if != NULL, the extra field information from the central header will be copied in to
149 extrafield_size is the size of the extraField buffer
150 comment if != NULL, the comment string of the file will be copied in to
151 comment_size is the size of the comment buffer */
153 extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, uint32_t len);
154 /* Read extra field from the current file (opened by unzOpenCurrentFile)
155 This is the local-header version of the extra field (sometimes, there is
156 more info in the local-header version than in the central-header)
158 if buf == NULL, it return the size of the local extra field
159 if buf != NULL, len is the size of the buffer, the extra header is copied in buf.
161 return number of bytes copied in buf, or (if <0) the error code */
163 extern int ZEXPORT unzCloseCurrentFile(unzFile file);
164 /* Close the file in zip opened with unzOpenCurrentFile
166 return UNZ_CRCERROR if all the file was read but the CRC is not good */
168 /***************************************************************************/
169 /* Browse the directory of the zipfile */
171 typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2);
172 typedef int (*unzIteratorFunction)(unzFile file);
173 typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename,
174 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
176 extern int ZEXPORT unzGoToFirstFile(unzFile file);
177 /* Set the current file of the zipfile to the first file.
179 return UNZ_OK if no error */
181 extern int ZEXPORT unzGoToFirstFile2(unzFile file, unz_file_info64 *pfile_info, char *filename,
182 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
183 /* Set the current file of the zipfile to the first file and retrieves the current info on success.
184 Not as seek intensive as unzGoToFirstFile + unzGetCurrentFileInfo.
186 return UNZ_OK if no error */
188 extern int ZEXPORT unzGoToNextFile(unzFile file);
189 /* Set the current file of the zipfile to the next file.
191 return UNZ_OK if no error
192 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
194 extern int ZEXPORT unzGoToNextFile2(unzFile file, unz_file_info64 *pfile_info, char *filename,
195 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
196 /* Set the current file of the zipfile to the next file and retrieves the current
197 info on success. Does less seeking around than unzGotoNextFile + unzGetCurrentFileInfo.
199 return UNZ_OK if no error
200 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
202 extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func);
203 /* Try locate the file szFileName in the zipfile. For custom filename comparison pass in comparison function.
205 return UNZ_OK if the file is found (it becomes the current file)
206 return UNZ_END_OF_LIST_OF_FILE if the file is not found */
208 /***************************************************************************/
209 /* Raw access to zip file */
211 typedef struct unz_file_pos_s
213 uint32_t pos_in_zip_directory; /* offset in zip file directory */
214 uint32_t num_of_file; /* # of file */
217 extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos);
218 extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos);
220 typedef struct unz64_file_pos_s
222 uint64_t pos_in_zip_directory; /* offset in zip file directory */
223 uint64_t num_of_file; /* # of file */
226 extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos);
227 extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos);
229 extern int32_t ZEXPORT unzGetOffset(unzFile file);
230 extern int64_t ZEXPORT unzGetOffset64(unzFile file);
231 /* Get the current file offset */
233 extern int ZEXPORT unzSetOffset(unzFile file, uint32_t pos);
234 extern int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos);
235 /* Set the current file offset */
237 extern int32_t ZEXPORT unzTell(unzFile file);
238 extern int64_t ZEXPORT unzTell64(unzFile file);
239 /* return current position in uncompressed data */
241 extern int ZEXPORT unzSeek(unzFile file, uint32_t offset, int origin);
242 extern int ZEXPORT unzSeek64(unzFile file, uint64_t offset, int origin);
243 /* Seek within the uncompressed data if compression method is storage */
245 extern int ZEXPORT unzEndOfFile(unzFile file);
246 /* return 1 if the end of file was reached, 0 elsewhere */
248 /***************************************************************************/