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
63 extern "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
88 typedef unzFile__ *unzFile;
89#else
90 typedef voidp unzFile;
91#endif
92
93#define UNZ_OK (0)
94#define UNZ_END_OF_LIST_OF_FILE (-100)
95#define UNZ_ERRNO (Z_ERRNO)
96#define UNZ_EOF (0)
97#define UNZ_PARAMERROR (-102)
98#define UNZ_BADZIPFILE (-103)
99#define UNZ_INTERNALERROR (-104)
100#define UNZ_CRCERROR (-105)
101
102 /* tm_unz contain date/time info */
103 typedef struct tm_unz_s
104 {
105 uInt tm_sec; /* seconds after the minute - [0,59] */
106 uInt tm_min; /* minutes after the hour - [0,59] */
107 uInt tm_hour; /* hours since midnight - [0,23] */
108 uInt tm_mday; /* day of the month - [1,31] */
109 uInt tm_mon; /* months since January - [0,11] */
110 uInt tm_year; /* years - [1980..2044] */
111 } tm_unz;
112
113 /* unz_global_info structure contain global data about the ZIPfile
114 These data comes from the end of central dir */
115 typedef struct unz_global_info_s
116 {
117 uLong64 number_entry; /* total number of entries in
118 the central dir on this disk */
119 uLong size_comment; /* size of the global comment of the zipfile */
120 } unz_global_info;
121
122 /* unz_file_info contain information about a file in the zipfile */
123 typedef struct unz_file_info_s
124 {
125 uLong version; /* version made by 2 bytes */
126 uLong version_needed; /* version needed to extract 2 bytes */
127 uLong flag; /* general purpose bit flag 2 bytes */
128 uLong compression_method; /* compression method 2 bytes */
129 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
130 uLong crc; /* crc-32 4 bytes */
131 uLong64 compressed_size; /* compressed size 4 bytes */
132 uLong64 uncompressed_size; /* uncompressed size 4 bytes */
133 uLong size_filename; /* filename length 2 bytes */
134 uLong64
135 file_extra_abs_offset; /* absolute offset in the file where file_extra is located */
136 uLong size_file_extra; /* extra field length 2 bytes */
137 uLong size_file_comment; /* file comment length 2 bytes */
138
139 uLong disk_num_start; /* disk number start 2 bytes */
140 uLong internal_fa; /* internal file attributes 2 bytes */
141 uLong external_fa; /* external file attributes 4 bytes */
142
143 tm_unz tmu_date;
144 } unz_file_info;
145
146 extern int ZEXPORT cpl_unzStringFileNameCompare(const char *fileName1,
147 const char *fileName2,
148 int iCaseSensitivity);
149 /*
150 Compare two filename (fileName1,fileName2).
151 If iCaseSenisivity = 1, comparison is case sensitivity (like strcmp)
152 If iCaseSenisivity = 2, comparison is not case sensitivity (like strcmpi
153 or strcasecmp)
154 If iCaseSenisivity = 0, case sensitivity is default of your operating
155 system (like 1 on Unix, 2 on Windows)
156 */
157
158 extern unzFile ZEXPORT cpl_unzOpen(const char *path);
159 /*
160 Open a Zip file. path contain the full pathname (by example,
161 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
162 "zlib/zlib113.zip".
163 If the zipfile cannot be opened (file don't exist or in not valid), the
164 return value is NULL.
165 Else, the return value is a unzFile Handle, usable with other function
166 of this unzip package.
167 */
168
169 extern unzFile ZEXPORT cpl_unzOpen2(const char *path,
170 zlib_filefunc_def *pzlib_filefunc_def);
171 /*
172 Open a Zip file, like unzOpen, but provide a set of file low level API
173 for read/write the zip file (see ioapi.h)
174 */
175
176 extern int ZEXPORT cpl_unzClose(unzFile file);
177 /*
178 Close a ZipFile opened with unzipOpen.
179 If there is files inside the .Zip opened with unzOpenCurrentFile (see
180 later), these files MUST be closed with unzipCloseCurrentFile before call
181 unzipClose. return UNZ_OK if there is no problem. */
182
183 extern int ZEXPORT cpl_unzGetGlobalInfo(unzFile file,
184 unz_global_info *pglobal_info);
185 /*
186 Write info about the ZipFile in the *pglobal_info structure.
187 No preparation of the structure is needed
188 return UNZ_OK if there is no problem. */
189
190 extern int ZEXPORT cpl_unzGetGlobalComment(unzFile file, char *szComment,
191 uLong uSizeBuf);
192 /*
193 Get the global comment string of the ZipFile, in the szComment buffer.
194 uSizeBuf is the size of the szComment buffer.
195 return the number of byte copied or an error code <0
196 */
197
198 /***************************************************************************/
199 /* Unzip package allow you browse the directory of the zipfile */
200
201 extern int ZEXPORT cpl_unzGoToFirstFile(unzFile file);
202 /*
203 Set the current file of the zipfile to the first file.
204 return UNZ_OK if there is no problem
205 */
206
207 extern int ZEXPORT cpl_unzGoToNextFile(unzFile file);
208 /*
209 Set the current file of the zipfile to the next file.
210 return UNZ_OK if there is no problem
211 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
212 */
213
214 extern int ZEXPORT cpl_unzLocateFile(unzFile file, const char *szFileName,
215 int iCaseSensitivity);
216
217 /*
218 Try locate the file szFileName in the zipfile.
219 For the iCaseSensitivity signification, see unzStringFileNameCompare
220
221 return value :
222 UNZ_OK if the file is found. It becomes the current file.
223 UNZ_END_OF_LIST_OF_FILE if the file is not found
224 */
225
226 /* ****************************************** */
227 /* Ryan supplied functions */
228 /* unz_file_info contain information about a file in the zipfile */
229 typedef struct unz_file_pos_s
230 {
231 uLong64 pos_in_zip_directory; /* offset in zip file directory */
232 uLong64 num_of_file; /* # of file */
233 } unz_file_pos;
234
235 extern int ZEXPORT cpl_unzGetFilePos(unzFile file, unz_file_pos *file_pos);
236
237 extern int ZEXPORT cpl_unzGoToFilePos(unzFile file, unz_file_pos *file_pos);
238
239 /* ****************************************** */
240
241 extern int ZEXPORT cpl_unzGetCurrentFileInfo(
242 unzFile file, unz_file_info *pfile_info, char *szFileName,
243 uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize,
244 char *szComment, uLong commentBufferSize);
245 /*
246 Get Info about the current file
247 if pfile_info!=NULL, the *pfile_info structure will contain some info
248 about the current file if szFileName!=NULL, the filename string will be
249 copied in szFileName (fileNameBufferSize is the size of the buffer) if
250 extraField!=NULL, the extra field information will be copied in extraField
251 (extraFieldBufferSize is the size of the buffer).
252 This is the Central-header version of the extra field
253 if szComment!=NULL, the comment string of the file will be copied in
254 szComment (commentBufferSize is the size of the buffer)
255 */
256
259 extern uLong64 ZEXPORT cpl_unzGetCurrentFileZStreamPos(unzFile file);
260
261 extern int cpl_unzGetLocalHeaderPos(unzFile file,
262 uLong64 *pos_local_header);
263
264 extern int cpl_unzCurrentFileInfoFromLocalHeader(
265 unzFile file, uLong64 pos_local_header, unz_file_info *pfile_info,
266 char *szFileName, size_t fileNameBufferSize, uLong64 *posData);
267
270 /***************************************************************************/
271 /* for reading the content of the current zipfile, you can open it, read
272 data from it, and close it (you can close it before reading all the file)
273 */
274
275 extern int ZEXPORT cpl_unzOpenCurrentFile(unzFile file);
276 /*
277 Open for reading data the current file in the zipfile.
278 If there is no error, the return value is UNZ_OK.
279 */
280
281 extern int ZEXPORT cpl_unzOpenCurrentFilePassword(unzFile file,
282 const char *password);
283 /*
284 Open for reading data the current file in the zipfile.
285 password is a crypting password
286 If there is no error, the return value is UNZ_OK.
287 */
288
289 extern int ZEXPORT cpl_unzOpenCurrentFile2(unzFile file, int *method,
290 int *level, int raw);
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_unzOpenCurrentFile3(unzFile file, int *method,
300 int *level, int raw,
301 const char *password);
302 /*
303 Same than unzOpenCurrentFile, but open for read raw the file (not
304 uncompress) if raw==1 *method will receive method of compression, *level
305 will receive level of compression note : you can set level parameter as
306 NULL (if you did not want known level, but you CANNOT set method parameter
307 as NULL
308 */
309
310 extern int ZEXPORT cpl_unzCloseCurrentFile(unzFile file);
311 /*
312 Close the file in zip opened with unzOpenCurrentFile
313 Return UNZ_CRCERROR if all the file was read but the CRC is not good
314 */
315
316 extern int ZEXPORT cpl_unzReadCurrentFile(unzFile file, voidp buf,
317 unsigned len);
318 /*
319 Read bytes from the current file (opened by unzOpenCurrentFile)
320 buf contain buffer where data must be copied
321 len the size of buf.
322
323 return the number of byte copied if some bytes are copied
324 return 0 if the end of file was reached
325 return <0 with error code if there is an error
326 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
327 */
328
329 extern z_off_t ZEXPORT cpl_unztell(unzFile file);
330 /*
331 Give the current position in uncompressed data
332 */
333
334 extern int ZEXPORT cpl_unzeof(unzFile file);
335 /*
336 return 1 if the end of file was reached, 0 elsewhere
337 */
338
339 extern int ZEXPORT cpl_unzGetLocalExtrafield(unzFile file, voidp buf,
340 unsigned len);
341 /*
342 Read extra field from the current file (opened by unzOpenCurrentFile)
343 This is the local-header version of the extra field (sometimes, there is
344 more info in the local-header version than in the central-header)
345
346 if buf==NULL, it return the size of the local extra field
347
348 if buf!=NULL, len is the size of the buffer, the extra header is copied in
349 buf.
350 the return value is the number of bytes copied in buf, or (if <0)
351 the error code
352 */
353
354 /***************************************************************************/
355
356 /* Get the current file offset */
357 extern uLong64 ZEXPORT cpl_unzGetOffset(unzFile file);
358
359 /* Set the current file offset */
360 extern int ZEXPORT cpl_unzSetOffset(unzFile file, uLong64 pos);
361
362#ifdef __cplusplus
363}
364#endif
365
366#endif /* #ifndef DOXYGEN_SKIP */
367
368#endif /* CPL_MINIZIP_UNZIP_H_INCLUDED */
cpl_vsi.h
Standard C Covers.