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