1 /* unzip.h -- IO for uncompress .zip files using zlib
2 Version 1.01h, December 28th, 2009
4 Copyright (C) 1998-2009 Gilles Vollant
6 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
7 WinZip, InfoZip tools and compatible.
9 Multi volume ZipFile (span) are not supported.
10 Encryption compatible with pkzip 2.04g only supported
11 Old compressions used by old PKZip 1.x are not supported
14 I WAIT FEEDBACK at mail info@winimage.com
15 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
17 Condition of use and distribution are the same than zlib :
19 This software is provided 'as-is', without any express or implied
20 warranty. In no event will the authors be held liable for any damages
21 arising from the use of this software.
23 Permission is granted to anyone to use this software for any purpose,
24 including commercial applications, and to alter it and redistribute it
25 freely, subject to the following restrictions:
27 1. The origin of this software must not be misrepresented; you must not
28 claim that you wrote the original software. If you use this software
29 in a product, an acknowledgment in the product documentation would be
30 appreciated but is not required.
31 2. Altered source versions must be plainly marked as such, and must not be
32 misrepresented as being the original software.
33 3. This notice may not be removed or altered from any source distribution.
38 /* for more info about .ZIP format, see
39 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
40 http://www.info-zip.org/pub/infozip/doc/
41 PkWare has also a specification at :
42 ftp://ftp.pkware.com/probdesc.zip
66 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
67 /* like the STRICT of WIN32, we define a pointer that cannot be converted
68 from (void*) without cast */
69 typedef struct TagunzFile__ { int unused; } unzFile__;
70 typedef unzFile__ *unzFile;
72 typedef voidp unzFile;
77 #define UNZ_END_OF_LIST_OF_FILE (-100)
78 #define UNZ_ERRNO (Z_ERRNO)
80 #define UNZ_PARAMERROR (-102)
81 #define UNZ_BADZIPFILE (-103)
82 #define UNZ_INTERNALERROR (-104)
83 #define UNZ_CRCERROR (-105)
85 /* tm_unz contain date/time info */
86 typedef struct tm_unz_s
88 uInt tm_sec; /* seconds after the minute - [0,59] */
89 uInt tm_min; /* minutes after the hour - [0,59] */
90 uInt tm_hour; /* hours since midnight - [0,23] */
91 uInt tm_mday; /* day of the month - [1,31] */
92 uInt tm_mon; /* months since January - [0,11] */
93 uInt tm_year; /* years - [1980..2044] */
96 /* unz_global_info structure contain global data about the ZIPfile
97 These data comes from the end of central dir */
98 typedef struct unz_global_info_s
100 uLong number_entry; /* total number of entries in
101 the central dir on this disk */
102 uLong size_comment; /* size of the global comment of the zipfile */
106 /* unz_file_info contain information about a file in the zipfile */
107 typedef struct unz_file_info_s
109 uLong version; /* version made by 2 bytes */
110 uLong version_needed; /* version needed to extract 2 bytes */
111 uLong flag; /* general purpose bit flag 2 bytes */
112 uLong compression_method; /* compression method 2 bytes */
113 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
114 uLong crc; /* crc-32 4 bytes */
115 uLong compressed_size; /* compressed size 4 bytes */
116 uLong uncompressed_size; /* uncompressed size 4 bytes */
117 uLong size_filename; /* filename length 2 bytes */
118 uLong size_file_extra; /* extra field length 2 bytes */
119 uLong size_file_comment; /* file comment length 2 bytes */
121 uLong disk_num_start; /* disk number start 2 bytes */
122 uLong internal_fa; /* internal file attributes 2 bytes */
123 uLong external_fa; /* external file attributes 4 bytes */
128 extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
129 const char* fileName2,
130 int iCaseSensitivity));
132 Compare two filename (fileName1,fileName2).
133 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
134 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
136 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
137 (like 1 on Unix, 2 on Windows)
141 extern unzFile ZEXPORT unzOpen OF((const char *path));
143 Open a Zip file. path contain the full pathname (by example,
144 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
146 If the zipfile cannot be opened (file don't exist or in not valid), the
147 return value is NULL.
148 Else, the return value is a unzFile Handle, usable with other function
149 of this unzip package.
152 extern unzFile ZEXPORT unzOpen2 OF((const char *path,
153 zlib_filefunc_def* pzlib_filefunc_def));
155 Open a Zip file, like unzOpen, but provide a set of file low level API
156 for read/write the zip file (see ioapi.h)
159 extern int ZEXPORT unzClose OF((unzFile file));
161 Close a ZipFile opened with unzipOpen.
162 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
163 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
164 return UNZ_OK if there is no problem. */
166 extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
167 unz_global_info *pglobal_info));
169 Write info about the ZipFile in the *pglobal_info structure.
170 No preparation of the structure is needed
171 return UNZ_OK if there is no problem. */
174 extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
178 Get the global comment string of the ZipFile, in the szComment buffer.
179 uSizeBuf is the size of the szComment buffer.
180 return the number of byte copied or an error code <0
184 /***************************************************************************/
185 /* Unzip package allow you browse the directory of the zipfile */
187 extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
189 Set the current file of the zipfile to the first file.
190 return UNZ_OK if there is no problem
193 extern int ZEXPORT unzGoToNextFile OF((unzFile file));
195 Set the current file of the zipfile to the next file.
196 return UNZ_OK if there is no problem
197 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
200 extern int ZEXPORT unzLocateFile OF((unzFile file,
201 const char *szFileName,
202 int iCaseSensitivity));
204 Try locate the file szFileName in the zipfile.
205 For the iCaseSensitivity signification, see unzStringFileNameCompare
208 UNZ_OK if the file is found. It becomes the current file.
209 UNZ_END_OF_LIST_OF_FILE if the file is not found
213 /* ****************************************** */
214 /* Ryan supplied functions */
215 /* unz_file_info contain information about a file in the zipfile */
216 typedef struct unz_file_pos_s
218 uLong pos_in_zip_directory; /* offset in zip file directory */
219 uLong num_of_file; /* # of file */
222 extern int ZEXPORT unzGetFilePos(
224 unz_file_pos* file_pos);
226 extern int ZEXPORT unzGoToFilePos(
228 unz_file_pos* file_pos);
230 /* ****************************************** */
232 extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
233 unz_file_info *pfile_info,
235 uLong fileNameBufferSize,
237 uLong extraFieldBufferSize,
239 uLong commentBufferSize));
241 Get Info about the current file
242 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
244 if szFileName!=NULL, the filemane string will be copied in szFileName
245 (fileNameBufferSize is the size of the buffer)
246 if extraField!=NULL, the extra field information will be copied in extraField
247 (extraFieldBufferSize is the size of the buffer).
248 This is the Central-header version of the extra field
249 if szComment!=NULL, the comment string of the file will be copied in szComment
250 (commentBufferSize is the size of the buffer)
253 /***************************************************************************/
254 /* for reading the content of the current zipfile, you can open it, read data
255 from it, and close it (you can close it before reading all the file)
258 extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
260 Open for reading data the current file in the zipfile.
261 If there is no error, the return value is UNZ_OK.
264 extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
265 const char* password));
267 Open for reading data the current file in the zipfile.
268 password is a crypting password
269 If there is no error, the return value is UNZ_OK.
272 extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
277 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
279 *method will receive method of compression, *level will receive level of
281 note : you can set level parameter as NULL (if you did not want known level,
282 but you CANNOT set method parameter as NULL
285 extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
289 const char* password));
291 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
293 *method will receive method of compression, *level will receive level of
295 note : you can set level parameter as NULL (if you did not want known level,
296 but you CANNOT set method parameter as NULL
300 extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
302 Close the file in zip opened with unzOpenCurrentFile
303 Return UNZ_CRCERROR if all the file was read but the CRC is not good
306 extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
310 Read bytes from the current file (opened by unzOpenCurrentFile)
311 buf contain buffer where data must be copied
314 return the number of byte copied if somes bytes are copied
315 return 0 if the end of file was reached
316 return <0 with error code if there is an error
317 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
320 extern z_off_t ZEXPORT unztell OF((unzFile file));
322 Give the current position in uncompressed data
325 extern int ZEXPORT unzeof OF((unzFile file));
327 return 1 if the end of file was reached, 0 elsewhere
330 extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
334 Read extra field from the current file (opened by unzOpenCurrentFile)
335 This is the local-header version of the extra field (sometimes, there is
336 more info in the local-header version than in the central-header)
338 if buf==NULL, it return the size of the local extra field
340 if buf!=NULL, len is the size of the buffer, the extra header is copied in
342 the return value is the number of bytes copied in buf, or (if <0)
346 /***************************************************************************/
348 /* Get the current file offset */
349 extern uLong ZEXPORT unzGetOffset (unzFile file);
351 /* Set the current file offset */
352 extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);