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