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