1 | /* unzip.h -- IO for uncompress .zip files using zlib
|
---|
2 | Version 1.00, September 10th, 2003
|
---|
3 |
|
---|
4 | Copyright (C) 1998-2003 Gilles Vollant
|
---|
5 |
|
---|
6 | This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
|
---|
7 | WinZip, InfoZip tools and compatible.
|
---|
8 | Encryption and multi volume ZipFile (span) are not supported.
|
---|
9 | Old compressions used by old PKZip 1.x are not supported
|
---|
10 |
|
---|
11 |
|
---|
12 | I WAIT FEEDBACK at mail [email protected]
|
---|
13 | Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
|
---|
14 |
|
---|
15 | Condition of use and distribution are the same than zlib :
|
---|
16 |
|
---|
17 | This software is provided 'as-is', without any express or implied
|
---|
18 | warranty. In no event will the authors be held liable for any damages
|
---|
19 | arising from the use of this software.
|
---|
20 |
|
---|
21 | Permission is granted to anyone to use this software for any purpose,
|
---|
22 | including commercial applications, and to alter it and redistribute it
|
---|
23 | freely, subject to the following restrictions:
|
---|
24 |
|
---|
25 | 1. The origin of this software must not be misrepresented; you must not
|
---|
26 | claim that you wrote the original software. If you use this software
|
---|
27 | in a product, an acknowledgment in the product documentation would be
|
---|
28 | appreciated but is not required.
|
---|
29 | 2. Altered source versions must be plainly marked as such, and must not be
|
---|
30 | misrepresented as being the original software.
|
---|
31 | 3. This notice may not be removed or altered from any source distribution.
|
---|
32 |
|
---|
33 |
|
---|
34 | */
|
---|
35 |
|
---|
36 | /* for more info about .ZIP format, see
|
---|
37 | http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
|
---|
38 | http://www.info-zip.org/pub/infozip/doc/
|
---|
39 | PkWare has also a specification at :
|
---|
40 | ftp://ftp.pkware.com/probdesc.zip
|
---|
41 | */
|
---|
42 |
|
---|
43 | #ifndef _unz_H
|
---|
44 | #define _unz_H
|
---|
45 |
|
---|
46 | #ifdef __cplusplus
|
---|
47 | extern "C" {
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | #ifndef _ZLIB_H
|
---|
51 | #include "zlib.h"
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | #ifndef _ZLIBIOAPI_H
|
---|
55 | #include "ioapi.h"
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
---|
59 | /* like the STRICT of WIN32, we define a pointer that cannot be converted
|
---|
60 | from (void*) without cast */
|
---|
61 | typedef struct TagunzFile__ { int unused; } unzFile__;
|
---|
62 | typedef unzFile__ *unzFile;
|
---|
63 | #else
|
---|
64 | typedef voidp unzFile;
|
---|
65 | #endif
|
---|
66 |
|
---|
67 |
|
---|
68 | #define UNZ_OK (0)
|
---|
69 | #define UNZ_END_OF_LIST_OF_FILE (-100)
|
---|
70 | #define UNZ_ERRNO (Z_ERRNO)
|
---|
71 | #define UNZ_EOF (0)
|
---|
72 | #define UNZ_PARAMERROR (-102)
|
---|
73 | #define UNZ_BADZIPFILE (-103)
|
---|
74 | #define UNZ_INTERNALERROR (-104)
|
---|
75 | #define UNZ_CRCERROR (-105)
|
---|
76 |
|
---|
77 | /* tm_unz contain date/time info */
|
---|
78 | typedef struct tm_unz_s
|
---|
79 | {
|
---|
80 | uInt tm_sec; /* seconds after the minute - [0,59] */
|
---|
81 | uInt tm_min; /* minutes after the hour - [0,59] */
|
---|
82 | uInt tm_hour; /* hours since midnight - [0,23] */
|
---|
83 | uInt tm_mday; /* day of the month - [1,31] */
|
---|
84 | uInt tm_mon; /* months since January - [0,11] */
|
---|
85 | uInt tm_year; /* years - [1980..2044] */
|
---|
86 | } tm_unz;
|
---|
87 |
|
---|
88 | /* unz_global_info structure contain global data about the ZIPfile
|
---|
89 | These data comes from the end of central dir */
|
---|
90 | typedef struct unz_global_info_s
|
---|
91 | {
|
---|
92 | uLong number_entry; /* total number of entries in
|
---|
93 | the central dir on this disk */
|
---|
94 | uLong size_comment; /* size of the global comment of the zipfile */
|
---|
95 | } unz_global_info;
|
---|
96 |
|
---|
97 |
|
---|
98 | /* unz_file_info contain information about a file in the zipfile */
|
---|
99 | typedef struct unz_file_info_s
|
---|
100 | {
|
---|
101 | uLong version; /* version made by 2 bytes */
|
---|
102 | uLong version_needed; /* version needed to extract 2 bytes */
|
---|
103 | uLong flag; /* general purpose bit flag 2 bytes */
|
---|
104 | uLong compression_method; /* compression method 2 bytes */
|
---|
105 | uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
---|
106 | uLong crc; /* crc-32 4 bytes */
|
---|
107 | uLong compressed_size; /* compressed size 4 bytes */
|
---|
108 | uLong uncompressed_size; /* uncompressed size 4 bytes */
|
---|
109 | uLong size_filename; /* filename length 2 bytes */
|
---|
110 | uLong size_file_extra; /* extra field length 2 bytes */
|
---|
111 | uLong size_file_comment; /* file comment length 2 bytes */
|
---|
112 |
|
---|
113 | uLong disk_num_start; /* disk number start 2 bytes */
|
---|
114 | uLong internal_fa; /* internal file attributes 2 bytes */
|
---|
115 | uLong external_fa; /* external file attributes 4 bytes */
|
---|
116 |
|
---|
117 | tm_unz tmu_date;
|
---|
118 | } unz_file_info;
|
---|
119 |
|
---|
120 | extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
|
---|
121 | const char* fileName2,
|
---|
122 | int iCaseSensitivity));
|
---|
123 | /*
|
---|
124 | Compare two filename (fileName1,fileName2).
|
---|
125 | If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
|
---|
126 | If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
|
---|
127 | or strcasecmp)
|
---|
128 | If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
|
---|
129 | (like 1 on Unix, 2 on Windows)
|
---|
130 | */
|
---|
131 |
|
---|
132 |
|
---|
133 | extern unzFile ZEXPORT unzOpen OF((const char *path));
|
---|
134 | /*
|
---|
135 | Open a Zip file. path contain the full pathname (by example,
|
---|
136 | on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
|
---|
137 | "zlib/zlib113.zip".
|
---|
138 | If the zipfile cannot be opened (file don't exist or in not valid), the
|
---|
139 | return value is NULL.
|
---|
140 | Else, the return value is a unzFile Handle, usable with other function
|
---|
141 | of this unzip package.
|
---|
142 | */
|
---|
143 |
|
---|
144 | extern unzFile ZEXPORT unzOpen2 OF((const char *path,
|
---|
145 | zlib_filefunc_def* pzlib_filefunc_def));
|
---|
146 | /*
|
---|
147 | Open a Zip file, like unzOpen, but provide a set of file low level API
|
---|
148 | for read/write the zip file (see ioapi.h)
|
---|
149 | */
|
---|
150 |
|
---|
151 | extern int ZEXPORT unzClose OF((unzFile file));
|
---|
152 | /*
|
---|
153 | Close a ZipFile opened with unzipOpen.
|
---|
154 | If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
|
---|
155 | these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
|
---|
156 | return UNZ_OK if there is no problem. */
|
---|
157 |
|
---|
158 | extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
|
---|
159 | unz_global_info *pglobal_info));
|
---|
160 | /*
|
---|
161 | Write info about the ZipFile in the *pglobal_info structure.
|
---|
162 | No preparation of the structure is needed
|
---|
163 | return UNZ_OK if there is no problem. */
|
---|
164 |
|
---|
165 |
|
---|
166 | extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
|
---|
167 | char *szComment,
|
---|
168 | uLong uSizeBuf));
|
---|
169 | /*
|
---|
170 | Get the global comment string of the ZipFile, in the szComment buffer.
|
---|
171 | uSizeBuf is the size of the szComment buffer.
|
---|
172 | return the number of byte copied or an error code <0
|
---|
173 | */
|
---|
174 |
|
---|
175 |
|
---|
176 | /***************************************************************************/
|
---|
177 | /* Unzip package allow you browse the directory of the zipfile */
|
---|
178 |
|
---|
179 | extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
|
---|
180 | /*
|
---|
181 | Set the current file of the zipfile to the first file.
|
---|
182 | return UNZ_OK if there is no problem
|
---|
183 | */
|
---|
184 |
|
---|
185 | extern int ZEXPORT unzGoToNextFile OF((unzFile file));
|
---|
186 | /*
|
---|
187 | Set the current file of the zipfile to the next file.
|
---|
188 | return UNZ_OK if there is no problem
|
---|
189 | return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
|
---|
190 | */
|
---|
191 |
|
---|
192 | extern int ZEXPORT unzLocateFile OF((unzFile file,
|
---|
193 | const char *szFileName,
|
---|
194 | int iCaseSensitivity));
|
---|
195 | /*
|
---|
196 | Try locate the file szFileName in the zipfile.
|
---|
197 | For the iCaseSensitivity signification, see unzStringFileNameCompare
|
---|
198 |
|
---|
199 | return value :
|
---|
200 | UNZ_OK if the file is found. It becomes the current file.
|
---|
201 | UNZ_END_OF_LIST_OF_FILE if the file is not found
|
---|
202 | */
|
---|
203 |
|
---|
204 |
|
---|
205 | /* ****************************************** */
|
---|
206 | /* Ryan supplied functions */
|
---|
207 | /* unz_file_info contain information about a file in the zipfile */
|
---|
208 | typedef struct unz_file_pos_s
|
---|
209 | {
|
---|
210 | uLong pos_in_zip_directory; /* offset in zip file directory */
|
---|
211 | uLong num_of_file; /* # of file */
|
---|
212 | } unz_file_pos;
|
---|
213 |
|
---|
214 | extern int ZEXPORT unzGetFilePos(
|
---|
215 | unzFile file,
|
---|
216 | unz_file_pos* file_pos);
|
---|
217 |
|
---|
218 | extern int ZEXPORT unzGoToFilePos(
|
---|
219 | unzFile file,
|
---|
220 | unz_file_pos* file_pos);
|
---|
221 |
|
---|
222 | /* ****************************************** */
|
---|
223 |
|
---|
224 | extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
|
---|
225 | unz_file_info *pfile_info,
|
---|
226 | char *szFileName,
|
---|
227 | uLong fileNameBufferSize,
|
---|
228 | void *extraField,
|
---|
229 | uLong extraFieldBufferSize,
|
---|
230 | char *szComment,
|
---|
231 | uLong commentBufferSize));
|
---|
232 | /*
|
---|
233 | Get Info about the current file
|
---|
234 | if pfile_info!=NULL, the *pfile_info structure will contain somes info about
|
---|
235 | the current file
|
---|
236 | if szFileName!=NULL, the filemane string will be copied in szFileName
|
---|
237 | (fileNameBufferSize is the size of the buffer)
|
---|
238 | if extraField!=NULL, the extra field information will be copied in extraField
|
---|
239 | (extraFieldBufferSize is the size of the buffer).
|
---|
240 | This is the Central-header version of the extra field
|
---|
241 | if szComment!=NULL, the comment string of the file will be copied in szComment
|
---|
242 | (commentBufferSize is the size of the buffer)
|
---|
243 | */
|
---|
244 |
|
---|
245 | /***************************************************************************/
|
---|
246 | /* for reading the content of the current zipfile, you can open it, read data
|
---|
247 | from it, and close it (you can close it before reading all the file)
|
---|
248 | */
|
---|
249 |
|
---|
250 | extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
|
---|
251 | /*
|
---|
252 | Open for reading data the current file in the zipfile.
|
---|
253 | If there is no error, the return value is UNZ_OK.
|
---|
254 | */
|
---|
255 |
|
---|
256 | extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
|
---|
257 | const char* password));
|
---|
258 | /*
|
---|
259 | Open for reading data the current file in the zipfile.
|
---|
260 | password is a crypting password
|
---|
261 | If there is no error, the return value is UNZ_OK.
|
---|
262 | */
|
---|
263 |
|
---|
264 | extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
|
---|
265 | int* method,
|
---|
266 | int* level,
|
---|
267 | int raw));
|
---|
268 | /*
|
---|
269 | Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
---|
270 | if raw==1
|
---|
271 | *method will receive method of compression, *level will receive level of
|
---|
272 | compression
|
---|
273 | note : you can set level parameter as NULL (if you did not want known level,
|
---|
274 | but you CANNOT set method parameter as NULL
|
---|
275 | */
|
---|
276 |
|
---|
277 | extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
|
---|
278 | int* method,
|
---|
279 | int* level,
|
---|
280 | int raw,
|
---|
281 | const char* password));
|
---|
282 | /*
|
---|
283 | Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
|
---|
284 | if raw==1
|
---|
285 | *method will receive method of compression, *level will receive level of
|
---|
286 | compression
|
---|
287 | note : you can set level parameter as NULL (if you did not want known level,
|
---|
288 | but you CANNOT set method parameter as NULL
|
---|
289 | */
|
---|
290 |
|
---|
291 |
|
---|
292 | extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
|
---|
293 | /*
|
---|
294 | Close the file in zip opened with unzOpenCurrentFile
|
---|
295 | Return UNZ_CRCERROR if all the file was read but the CRC is not good
|
---|
296 | */
|
---|
297 |
|
---|
298 | extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
|
---|
299 | voidp buf,
|
---|
300 | unsigned len));
|
---|
301 | /*
|
---|
302 | Read bytes from the current file (opened by unzOpenCurrentFile)
|
---|
303 | buf contain buffer where data must be copied
|
---|
304 | len the size of buf.
|
---|
305 |
|
---|
306 | return the number of byte copied if somes bytes are copied
|
---|
307 | return 0 if the end of file was reached
|
---|
308 | return <0 with error code if there is an error
|
---|
309 | (UNZ_ERRNO for IO error, or zLib error for uncompress error)
|
---|
310 | */
|
---|
311 |
|
---|
312 | extern z_off_t ZEXPORT unztell OF((unzFile file));
|
---|
313 | /*
|
---|
314 | Give the current position in uncompressed data
|
---|
315 | */
|
---|
316 |
|
---|
317 | extern int ZEXPORT unzeof OF((unzFile file));
|
---|
318 | /*
|
---|
319 | return 1 if the end of file was reached, 0 elsewhere
|
---|
320 | */
|
---|
321 |
|
---|
322 | extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
|
---|
323 | voidp buf,
|
---|
324 | unsigned len));
|
---|
325 | /*
|
---|
326 | Read extra field from the current file (opened by unzOpenCurrentFile)
|
---|
327 | This is the local-header version of the extra field (sometimes, there is
|
---|
328 | more info in the local-header version than in the central-header)
|
---|
329 |
|
---|
330 | if buf==NULL, it return the size of the local extra field
|
---|
331 |
|
---|
332 | if buf!=NULL, len is the size of the buffer, the extra header is copied in
|
---|
333 | buf.
|
---|
334 | the return value is the number of bytes copied in buf, or (if <0)
|
---|
335 | the error code
|
---|
336 | */
|
---|
337 |
|
---|
338 | #ifdef __cplusplus
|
---|
339 | }
|
---|
340 | #endif
|
---|
341 |
|
---|
342 | #endif /* _unz_H */
|
---|