GDAL

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