1 /* unzip.h -- IO for uncompress .zip files using zlib
\r
2 Version 1.01e, February 12th, 2005
\r
4 Copyright (C) 1998-2005 Gilles Vollant
\r
6 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
\r
7 WinZip, InfoZip tools and compatible.
\r
9 Multi volume ZipFile (span) are not supported.
\r
10 Encryption compatible with pkzip 2.04g only supported
\r
11 Old compressions used by old PKZip 1.x are not supported
\r
14 I WAIT FEEDBACK at mail info@winimage.com
\r
15 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
\r
17 Condition of use and distribution are the same than zlib :
\r
19 This software is provided 'as-is', without any express or implied
\r
20 warranty. In no event will the authors be held liable for any damages
\r
21 arising from the use of this software.
\r
23 Permission is granted to anyone to use this software for any purpose,
\r
24 including commercial applications, and to alter it and redistribute it
\r
25 freely, subject to the following restrictions:
\r
27 1. The origin of this software must not be misrepresented; you must not
\r
28 claim that you wrote the original software. If you use this software
\r
29 in a product, an acknowledgment in the product documentation would be
\r
30 appreciated but is not required.
\r
31 2. Altered source versions must be plainly marked as such, and must not be
\r
32 misrepresented as being the original software.
\r
33 3. This notice may not be removed or altered from any source distribution.
\r
38 /* for more info about .ZIP format, see
\r
39 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
\r
40 http://www.info-zip.org/pub/infozip/doc/
\r
41 PkWare has also a specification at :
\r
42 ftp://ftp.pkware.com/probdesc.zip
\r
56 #ifndef _ZLIBIOAPI_H
\r
60 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
\r
61 /* like the STRICT of WIN32, we define a pointer that cannot be converted
\r
62 from (void*) without cast */
\r
63 typedef struct TagunzFile__ { int unused; } unzFile__;
\r
64 typedef unzFile__ *unzFile;
\r
66 typedef voidp unzFile;
\r
71 #define UNZ_END_OF_LIST_OF_FILE (-100)
\r
72 #define UNZ_ERRNO (Z_ERRNO)
\r
74 #define UNZ_PARAMERROR (-102)
\r
75 #define UNZ_BADZIPFILE (-103)
\r
76 #define UNZ_INTERNALERROR (-104)
\r
77 #define UNZ_CRCERROR (-105)
\r
79 /* tm_unz contain date/time info */
\r
80 typedef struct tm_unz_s
\r
82 uInt tm_sec; /* seconds after the minute - [0,59] */
\r
83 uInt tm_min; /* minutes after the hour - [0,59] */
\r
84 uInt tm_hour; /* hours since midnight - [0,23] */
\r
85 uInt tm_mday; /* day of the month - [1,31] */
\r
86 uInt tm_mon; /* months since January - [0,11] */
\r
87 uInt tm_year; /* years - [1980..2044] */
\r
90 /* unz_global_info structure contain global data about the ZIPfile
\r
91 These data comes from the end of central dir */
\r
92 typedef struct unz_global_info_s
\r
94 uLong number_entry; /* total number of entries in
\r
95 the central dir on this disk */
\r
96 uLong size_comment; /* size of the global comment of the zipfile */
\r
100 /* unz_file_info contain information about a file in the zipfile */
\r
101 typedef struct unz_file_info_s
\r
103 uLong version; /* version made by 2 bytes */
\r
104 uLong version_needed; /* version needed to extract 2 bytes */
\r
105 uLong flag; /* general purpose bit flag 2 bytes */
\r
106 uLong compression_method; /* compression method 2 bytes */
\r
107 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
\r
108 uLong crc; /* crc-32 4 bytes */
\r
109 uLong compressed_size; /* compressed size 4 bytes */
\r
110 uLong uncompressed_size; /* uncompressed size 4 bytes */
\r
111 uLong size_filename; /* filename length 2 bytes */
\r
112 uLong size_file_extra; /* extra field length 2 bytes */
\r
113 uLong size_file_comment; /* file comment length 2 bytes */
\r
115 uLong disk_num_start; /* disk number start 2 bytes */
\r
116 uLong internal_fa; /* internal file attributes 2 bytes */
\r
117 uLong external_fa; /* external file attributes 4 bytes */
\r
122 extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
\r
123 const char* fileName2,
\r
124 int iCaseSensitivity));
\r
126 Compare two filename (fileName1,fileName2).
\r
127 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
\r
128 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
\r
130 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
\r
131 (like 1 on Unix, 2 on Windows)
\r
135 extern unzFile ZEXPORT unzOpen OF((const char *path));
\r
137 Open a Zip file. path contain the full pathname (by example,
\r
138 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
\r
139 "zlib/zlib113.zip".
\r
140 If the zipfile cannot be opened (file don't exist or in not valid), the
\r
141 return value is NULL.
\r
142 Else, the return value is a unzFile Handle, usable with other function
\r
143 of this unzip package.
\r
146 extern unzFile ZEXPORT unzOpen2 OF((const char *path,
\r
147 zlib_filefunc_def* pzlib_filefunc_def));
\r
149 Open a Zip file, like unzOpen, but provide a set of file low level API
\r
150 for read/write the zip file (see ioapi.h)
\r
153 extern int ZEXPORT unzClose OF((unzFile file));
\r
155 Close a ZipFile opened with unzipOpen.
\r
156 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
\r
157 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
\r
158 return UNZ_OK if there is no problem. */
\r
160 extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
\r
161 unz_global_info *pglobal_info));
\r
163 Write info about the ZipFile in the *pglobal_info structure.
\r
164 No preparation of the structure is needed
\r
165 return UNZ_OK if there is no problem. */
\r
168 extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
\r
172 Get the global comment string of the ZipFile, in the szComment buffer.
\r
173 uSizeBuf is the size of the szComment buffer.
\r
174 return the number of byte copied or an error code <0
\r
178 /***************************************************************************/
\r
179 /* Unzip package allow you browse the directory of the zipfile */
\r
181 extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
\r
183 Set the current file of the zipfile to the first file.
\r
184 return UNZ_OK if there is no problem
\r
187 extern int ZEXPORT unzGoToNextFile OF((unzFile file));
\r
189 Set the current file of the zipfile to the next file.
\r
190 return UNZ_OK if there is no problem
\r
191 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
\r
194 extern int ZEXPORT unzLocateFile OF((unzFile file,
\r
195 const char *szFileName,
\r
196 int iCaseSensitivity));
\r
198 Try locate the file szFileName in the zipfile.
\r
199 For the iCaseSensitivity signification, see unzStringFileNameCompare
\r
202 UNZ_OK if the file is found. It becomes the current file.
\r
203 UNZ_END_OF_LIST_OF_FILE if the file is not found
\r
207 /* ****************************************** */
\r
208 /* Ryan supplied functions */
\r
209 /* unz_file_info contain information about a file in the zipfile */
\r
210 typedef struct unz_file_pos_s
\r
212 uLong pos_in_zip_directory; /* offset in zip file directory */
\r
213 uLong num_of_file; /* # of file */
\r
216 extern int ZEXPORT unzGetFilePos(
\r
218 unz_file_pos* file_pos);
\r
220 extern int ZEXPORT unzGoToFilePos(
\r
222 unz_file_pos* file_pos);
\r
224 /* ****************************************** */
\r
226 extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
\r
227 unz_file_info *pfile_info,
\r
229 uLong fileNameBufferSize,
\r
231 uLong extraFieldBufferSize,
\r
233 uLong commentBufferSize));
\r
235 Get Info about the current file
\r
236 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
\r
238 if szFileName!=NULL, the filemane string will be copied in szFileName
\r
239 (fileNameBufferSize is the size of the buffer)
\r
240 if extraField!=NULL, the extra field information will be copied in extraField
\r
241 (extraFieldBufferSize is the size of the buffer).
\r
242 This is the Central-header version of the extra field
\r
243 if szComment!=NULL, the comment string of the file will be copied in szComment
\r
244 (commentBufferSize is the size of the buffer)
\r
247 /***************************************************************************/
\r
248 /* for reading the content of the current zipfile, you can open it, read data
\r
249 from it, and close it (you can close it before reading all the file)
\r
252 extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
\r
254 Open for reading data the current file in the zipfile.
\r
255 If there is no error, the return value is UNZ_OK.
\r
258 extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
\r
259 const char* password));
\r
261 Open for reading data the current file in the zipfile.
\r
262 password is a crypting password
\r
263 If there is no error, the return value is UNZ_OK.
\r
266 extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
\r
271 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
\r
273 *method will receive method of compression, *level will receive level of
\r
275 note : you can set level parameter as NULL (if you did not want known level,
\r
276 but you CANNOT set method parameter as NULL
\r
279 extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
\r
283 const char* password));
\r
285 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
\r
287 *method will receive method of compression, *level will receive level of
\r
289 note : you can set level parameter as NULL (if you did not want known level,
\r
290 but you CANNOT set method parameter as NULL
\r
294 extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
\r
296 Close the file in zip opened with unzOpenCurrentFile
\r
297 Return UNZ_CRCERROR if all the file was read but the CRC is not good
\r
300 extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
\r
304 Read bytes from the current file (opened by unzOpenCurrentFile)
\r
305 buf contain buffer where data must be copied
\r
306 len the size of buf.
\r
308 return the number of byte copied if somes bytes are copied
\r
309 return 0 if the end of file was reached
\r
310 return <0 with error code if there is an error
\r
311 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
\r
314 extern z_off_t ZEXPORT unztell OF((unzFile file));
\r
316 Give the current position in uncompressed data
\r
319 extern int ZEXPORT unzeof OF((unzFile file));
\r
321 return 1 if the end of file was reached, 0 elsewhere
\r
324 extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
\r
328 Read extra field from the current file (opened by unzOpenCurrentFile)
\r
329 This is the local-header version of the extra field (sometimes, there is
\r
330 more info in the local-header version than in the central-header)
\r
332 if buf==NULL, it return the size of the local extra field
\r
334 if buf!=NULL, len is the size of the buffer, the extra header is copied in
\r
336 the return value is the number of bytes copied in buf, or (if <0)
\r
340 /***************************************************************************/
\r
342 /* Get the current file offset */
\r
343 extern uLong ZEXPORT unzGetOffset (unzFile file);
\r
345 /* Set the current file offset */
\r
346 extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
\r
354 #endif /* _unz_H */
\r