unzip.h revision 1.1.1.2 1 1.1 christos /* unzip.h -- IO for uncompress .zip files using zlib
2 1.1.1.2 christos Version 1.1, February 14h, 2010
3 1.1.1.2 christos part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
4 1.1 christos
5 1.1.1.2 christos Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
6 1.1 christos
7 1.1.1.2 christos Modifications of Unzip for Zip64
8 1.1.1.2 christos Copyright (C) 2007-2008 Even Rouault
9 1.1 christos
10 1.1.1.2 christos Modifications for Zip64 support on both zip and unzip
11 1.1.1.2 christos Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
12 1.1 christos
13 1.1.1.2 christos For more info read MiniZip_info.txt
14 1.1 christos
15 1.1.1.2 christos ---------------------------------------------------------------------------------
16 1.1 christos
17 1.1.1.2 christos Condition of use and distribution are the same than zlib :
18 1.1 christos
19 1.1 christos This software is provided 'as-is', without any express or implied
20 1.1 christos warranty. In no event will the authors be held liable for any damages
21 1.1 christos arising from the use of this software.
22 1.1 christos
23 1.1 christos Permission is granted to anyone to use this software for any purpose,
24 1.1 christos including commercial applications, and to alter it and redistribute it
25 1.1 christos freely, subject to the following restrictions:
26 1.1 christos
27 1.1 christos 1. The origin of this software must not be misrepresented; you must not
28 1.1 christos claim that you wrote the original software. If you use this software
29 1.1 christos in a product, an acknowledgment in the product documentation would be
30 1.1 christos appreciated but is not required.
31 1.1 christos 2. Altered source versions must be plainly marked as such, and must not be
32 1.1 christos misrepresented as being the original software.
33 1.1 christos 3. This notice may not be removed or altered from any source distribution.
34 1.1 christos
35 1.1.1.2 christos ---------------------------------------------------------------------------------
36 1.1 christos
37 1.1.1.2 christos Changes
38 1.1.1.2 christos
39 1.1.1.2 christos See header of unzip64.c
40 1.1 christos
41 1.1 christos */
42 1.1 christos
43 1.1.1.2 christos #ifndef _unz64_H
44 1.1.1.2 christos #define _unz64_H
45 1.1 christos
46 1.1 christos #ifdef __cplusplus
47 1.1 christos extern "C" {
48 1.1 christos #endif
49 1.1 christos
50 1.1 christos #ifndef _ZLIB_H
51 1.1 christos #include "zlib.h"
52 1.1 christos #endif
53 1.1 christos
54 1.1.1.2 christos #ifndef _ZLIBIOAPI_H
55 1.1 christos #include "ioapi.h"
56 1.1 christos #endif
57 1.1 christos
58 1.1.1.2 christos #ifdef HAVE_BZIP2
59 1.1.1.2 christos #include "bzlib.h"
60 1.1.1.2 christos #endif
61 1.1.1.2 christos
62 1.1.1.2 christos #define Z_BZIP2ED 12
63 1.1.1.2 christos
64 1.1 christos #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
65 1.1 christos /* like the STRICT of WIN32, we define a pointer that cannot be converted
66 1.1 christos from (void*) without cast */
67 1.1 christos typedef struct TagunzFile__ { int unused; } unzFile__;
68 1.1 christos typedef unzFile__ *unzFile;
69 1.1 christos #else
70 1.1 christos typedef voidp unzFile;
71 1.1 christos #endif
72 1.1 christos
73 1.1 christos
74 1.1 christos #define UNZ_OK (0)
75 1.1 christos #define UNZ_END_OF_LIST_OF_FILE (-100)
76 1.1 christos #define UNZ_ERRNO (Z_ERRNO)
77 1.1 christos #define UNZ_EOF (0)
78 1.1 christos #define UNZ_PARAMERROR (-102)
79 1.1 christos #define UNZ_BADZIPFILE (-103)
80 1.1 christos #define UNZ_INTERNALERROR (-104)
81 1.1 christos #define UNZ_CRCERROR (-105)
82 1.1 christos
83 1.1 christos /* tm_unz contain date/time info */
84 1.1 christos typedef struct tm_unz_s
85 1.1 christos {
86 1.1 christos uInt tm_sec; /* seconds after the minute - [0,59] */
87 1.1 christos uInt tm_min; /* minutes after the hour - [0,59] */
88 1.1 christos uInt tm_hour; /* hours since midnight - [0,23] */
89 1.1 christos uInt tm_mday; /* day of the month - [1,31] */
90 1.1 christos uInt tm_mon; /* months since January - [0,11] */
91 1.1 christos uInt tm_year; /* years - [1980..2044] */
92 1.1 christos } tm_unz;
93 1.1 christos
94 1.1 christos /* unz_global_info structure contain global data about the ZIPfile
95 1.1 christos These data comes from the end of central dir */
96 1.1.1.2 christos typedef struct unz_global_info64_s
97 1.1.1.2 christos {
98 1.1.1.2 christos ZPOS64_T number_entry; /* total number of entries in
99 1.1.1.2 christos the central dir on this disk */
100 1.1.1.2 christos uLong size_comment; /* size of the global comment of the zipfile */
101 1.1.1.2 christos } unz_global_info64;
102 1.1.1.2 christos
103 1.1 christos typedef struct unz_global_info_s
104 1.1 christos {
105 1.1 christos uLong number_entry; /* total number of entries in
106 1.1.1.2 christos the central dir on this disk */
107 1.1 christos uLong size_comment; /* size of the global comment of the zipfile */
108 1.1 christos } unz_global_info;
109 1.1 christos
110 1.1 christos /* unz_file_info contain information about a file in the zipfile */
111 1.1.1.2 christos typedef struct unz_file_info64_s
112 1.1.1.2 christos {
113 1.1.1.2 christos uLong version; /* version made by 2 bytes */
114 1.1.1.2 christos uLong version_needed; /* version needed to extract 2 bytes */
115 1.1.1.2 christos uLong flag; /* general purpose bit flag 2 bytes */
116 1.1.1.2 christos uLong compression_method; /* compression method 2 bytes */
117 1.1.1.2 christos uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
118 1.1.1.2 christos uLong crc; /* crc-32 4 bytes */
119 1.1.1.2 christos ZPOS64_T compressed_size; /* compressed size 8 bytes */
120 1.1.1.2 christos ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
121 1.1.1.2 christos uLong size_filename; /* filename length 2 bytes */
122 1.1.1.2 christos uLong size_file_extra; /* extra field length 2 bytes */
123 1.1.1.2 christos uLong size_file_comment; /* file comment length 2 bytes */
124 1.1.1.2 christos
125 1.1.1.2 christos uLong disk_num_start; /* disk number start 2 bytes */
126 1.1.1.2 christos uLong internal_fa; /* internal file attributes 2 bytes */
127 1.1.1.2 christos uLong external_fa; /* external file attributes 4 bytes */
128 1.1.1.2 christos
129 1.1.1.2 christos tm_unz tmu_date;
130 1.1.1.2 christos } unz_file_info64;
131 1.1.1.2 christos
132 1.1 christos typedef struct unz_file_info_s
133 1.1 christos {
134 1.1 christos uLong version; /* version made by 2 bytes */
135 1.1 christos uLong version_needed; /* version needed to extract 2 bytes */
136 1.1 christos uLong flag; /* general purpose bit flag 2 bytes */
137 1.1 christos uLong compression_method; /* compression method 2 bytes */
138 1.1 christos uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
139 1.1 christos uLong crc; /* crc-32 4 bytes */
140 1.1 christos uLong compressed_size; /* compressed size 4 bytes */
141 1.1 christos uLong uncompressed_size; /* uncompressed size 4 bytes */
142 1.1 christos uLong size_filename; /* filename length 2 bytes */
143 1.1 christos uLong size_file_extra; /* extra field length 2 bytes */
144 1.1 christos uLong size_file_comment; /* file comment length 2 bytes */
145 1.1 christos
146 1.1 christos uLong disk_num_start; /* disk number start 2 bytes */
147 1.1 christos uLong internal_fa; /* internal file attributes 2 bytes */
148 1.1 christos uLong external_fa; /* external file attributes 4 bytes */
149 1.1 christos
150 1.1 christos tm_unz tmu_date;
151 1.1 christos } unz_file_info;
152 1.1 christos
153 1.1 christos extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
154 1.1 christos const char* fileName2,
155 1.1 christos int iCaseSensitivity));
156 1.1 christos /*
157 1.1 christos Compare two filename (fileName1,fileName2).
158 1.1 christos If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
159 1.1 christos If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
160 1.1 christos or strcasecmp)
161 1.1 christos If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
162 1.1 christos (like 1 on Unix, 2 on Windows)
163 1.1 christos */
164 1.1 christos
165 1.1 christos
166 1.1 christos extern unzFile ZEXPORT unzOpen OF((const char *path));
167 1.1.1.2 christos extern unzFile ZEXPORT unzOpen64 OF((const void *path));
168 1.1 christos /*
169 1.1 christos Open a Zip file. path contain the full pathname (by example,
170 1.1 christos on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
171 1.1 christos "zlib/zlib113.zip".
172 1.1 christos If the zipfile cannot be opened (file don't exist or in not valid), the
173 1.1 christos return value is NULL.
174 1.1 christos Else, the return value is a unzFile Handle, usable with other function
175 1.1 christos of this unzip package.
176 1.1.1.2 christos the "64" function take a const void* pointer, because the path is just the
177 1.1.1.2 christos value passed to the open64_file_func callback.
178 1.1.1.2 christos Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
179 1.1.1.2 christos is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
180 1.1.1.2 christos does not describe the reality
181 1.1 christos */
182 1.1 christos
183 1.1.1.2 christos
184 1.1 christos extern unzFile ZEXPORT unzOpen2 OF((const char *path,
185 1.1 christos zlib_filefunc_def* pzlib_filefunc_def));
186 1.1 christos /*
187 1.1 christos Open a Zip file, like unzOpen, but provide a set of file low level API
188 1.1 christos for read/write the zip file (see ioapi.h)
189 1.1 christos */
190 1.1 christos
191 1.1.1.2 christos extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
192 1.1.1.2 christos zlib_filefunc64_def* pzlib_filefunc_def));
193 1.1.1.2 christos /*
194 1.1.1.2 christos Open a Zip file, like unz64Open, but provide a set of file low level API
195 1.1.1.2 christos for read/write the zip file (see ioapi.h)
196 1.1.1.2 christos */
197 1.1.1.2 christos
198 1.1 christos extern int ZEXPORT unzClose OF((unzFile file));
199 1.1 christos /*
200 1.1.1.2 christos Close a ZipFile opened with unzOpen.
201 1.1 christos If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
202 1.1.1.2 christos these files MUST be closed with unzCloseCurrentFile before call unzClose.
203 1.1 christos return UNZ_OK if there is no problem. */
204 1.1 christos
205 1.1 christos extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
206 1.1 christos unz_global_info *pglobal_info));
207 1.1.1.2 christos
208 1.1.1.2 christos extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
209 1.1.1.2 christos unz_global_info64 *pglobal_info));
210 1.1 christos /*
211 1.1 christos Write info about the ZipFile in the *pglobal_info structure.
212 1.1 christos No preparation of the structure is needed
213 1.1 christos return UNZ_OK if there is no problem. */
214 1.1 christos
215 1.1 christos
216 1.1 christos extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
217 1.1 christos char *szComment,
218 1.1 christos uLong uSizeBuf));
219 1.1 christos /*
220 1.1 christos Get the global comment string of the ZipFile, in the szComment buffer.
221 1.1 christos uSizeBuf is the size of the szComment buffer.
222 1.1 christos return the number of byte copied or an error code <0
223 1.1 christos */
224 1.1 christos
225 1.1 christos
226 1.1 christos /***************************************************************************/
227 1.1 christos /* Unzip package allow you browse the directory of the zipfile */
228 1.1 christos
229 1.1 christos extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
230 1.1 christos /*
231 1.1 christos Set the current file of the zipfile to the first file.
232 1.1 christos return UNZ_OK if there is no problem
233 1.1 christos */
234 1.1 christos
235 1.1 christos extern int ZEXPORT unzGoToNextFile OF((unzFile file));
236 1.1 christos /*
237 1.1 christos Set the current file of the zipfile to the next file.
238 1.1 christos return UNZ_OK if there is no problem
239 1.1 christos return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
240 1.1 christos */
241 1.1 christos
242 1.1 christos extern int ZEXPORT unzLocateFile OF((unzFile file,
243 1.1 christos const char *szFileName,
244 1.1 christos int iCaseSensitivity));
245 1.1 christos /*
246 1.1 christos Try locate the file szFileName in the zipfile.
247 1.1 christos For the iCaseSensitivity signification, see unzStringFileNameCompare
248 1.1 christos
249 1.1 christos return value :
250 1.1 christos UNZ_OK if the file is found. It becomes the current file.
251 1.1 christos UNZ_END_OF_LIST_OF_FILE if the file is not found
252 1.1 christos */
253 1.1 christos
254 1.1 christos
255 1.1 christos /* ****************************************** */
256 1.1 christos /* Ryan supplied functions */
257 1.1 christos /* unz_file_info contain information about a file in the zipfile */
258 1.1 christos typedef struct unz_file_pos_s
259 1.1 christos {
260 1.1 christos uLong pos_in_zip_directory; /* offset in zip file directory */
261 1.1 christos uLong num_of_file; /* # of file */
262 1.1 christos } unz_file_pos;
263 1.1 christos
264 1.1 christos extern int ZEXPORT unzGetFilePos(
265 1.1 christos unzFile file,
266 1.1 christos unz_file_pos* file_pos);
267 1.1 christos
268 1.1 christos extern int ZEXPORT unzGoToFilePos(
269 1.1 christos unzFile file,
270 1.1 christos unz_file_pos* file_pos);
271 1.1 christos
272 1.1.1.2 christos typedef struct unz64_file_pos_s
273 1.1.1.2 christos {
274 1.1.1.2 christos ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
275 1.1.1.2 christos ZPOS64_T num_of_file; /* # of file */
276 1.1.1.2 christos } unz64_file_pos;
277 1.1.1.2 christos
278 1.1.1.2 christos extern int ZEXPORT unzGetFilePos64(
279 1.1.1.2 christos unzFile file,
280 1.1.1.2 christos unz64_file_pos* file_pos);
281 1.1.1.2 christos
282 1.1.1.2 christos extern int ZEXPORT unzGoToFilePos64(
283 1.1.1.2 christos unzFile file,
284 1.1.1.2 christos const unz64_file_pos* file_pos);
285 1.1.1.2 christos
286 1.1 christos /* ****************************************** */
287 1.1 christos
288 1.1.1.2 christos extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
289 1.1.1.2 christos unz_file_info64 *pfile_info,
290 1.1.1.2 christos char *szFileName,
291 1.1.1.2 christos uLong fileNameBufferSize,
292 1.1.1.2 christos void *extraField,
293 1.1.1.2 christos uLong extraFieldBufferSize,
294 1.1.1.2 christos char *szComment,
295 1.1.1.2 christos uLong commentBufferSize));
296 1.1.1.2 christos
297 1.1 christos extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
298 1.1 christos unz_file_info *pfile_info,
299 1.1 christos char *szFileName,
300 1.1 christos uLong fileNameBufferSize,
301 1.1 christos void *extraField,
302 1.1 christos uLong extraFieldBufferSize,
303 1.1 christos char *szComment,
304 1.1 christos uLong commentBufferSize));
305 1.1 christos /*
306 1.1 christos Get Info about the current file
307 1.1 christos if pfile_info!=NULL, the *pfile_info structure will contain somes info about
308 1.1 christos the current file
309 1.1 christos if szFileName!=NULL, the filemane string will be copied in szFileName
310 1.1 christos (fileNameBufferSize is the size of the buffer)
311 1.1 christos if extraField!=NULL, the extra field information will be copied in extraField
312 1.1 christos (extraFieldBufferSize is the size of the buffer).
313 1.1 christos This is the Central-header version of the extra field
314 1.1 christos if szComment!=NULL, the comment string of the file will be copied in szComment
315 1.1 christos (commentBufferSize is the size of the buffer)
316 1.1 christos */
317 1.1 christos
318 1.1.1.2 christos
319 1.1.1.2 christos /** Addition for GDAL : START */
320 1.1.1.2 christos
321 1.1.1.2 christos extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
322 1.1.1.2 christos
323 1.1.1.2 christos /** Addition for GDAL : END */
324 1.1.1.2 christos
325 1.1.1.2 christos
326 1.1 christos /***************************************************************************/
327 1.1 christos /* for reading the content of the current zipfile, you can open it, read data
328 1.1 christos from it, and close it (you can close it before reading all the file)
329 1.1 christos */
330 1.1 christos
331 1.1 christos extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
332 1.1 christos /*
333 1.1 christos Open for reading data the current file in the zipfile.
334 1.1 christos If there is no error, the return value is UNZ_OK.
335 1.1 christos */
336 1.1 christos
337 1.1 christos extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
338 1.1 christos const char* password));
339 1.1 christos /*
340 1.1 christos Open for reading data the current file in the zipfile.
341 1.1 christos password is a crypting password
342 1.1 christos If there is no error, the return value is UNZ_OK.
343 1.1 christos */
344 1.1 christos
345 1.1 christos extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
346 1.1 christos int* method,
347 1.1 christos int* level,
348 1.1 christos int raw));
349 1.1 christos /*
350 1.1 christos Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
351 1.1 christos if raw==1
352 1.1 christos *method will receive method of compression, *level will receive level of
353 1.1 christos compression
354 1.1 christos note : you can set level parameter as NULL (if you did not want known level,
355 1.1 christos but you CANNOT set method parameter as NULL
356 1.1 christos */
357 1.1 christos
358 1.1 christos extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
359 1.1 christos int* method,
360 1.1 christos int* level,
361 1.1 christos int raw,
362 1.1 christos const char* password));
363 1.1 christos /*
364 1.1 christos Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
365 1.1 christos if raw==1
366 1.1 christos *method will receive method of compression, *level will receive level of
367 1.1 christos compression
368 1.1 christos note : you can set level parameter as NULL (if you did not want known level,
369 1.1 christos but you CANNOT set method parameter as NULL
370 1.1 christos */
371 1.1 christos
372 1.1 christos
373 1.1 christos extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
374 1.1 christos /*
375 1.1 christos Close the file in zip opened with unzOpenCurrentFile
376 1.1 christos Return UNZ_CRCERROR if all the file was read but the CRC is not good
377 1.1 christos */
378 1.1 christos
379 1.1 christos extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
380 1.1 christos voidp buf,
381 1.1 christos unsigned len));
382 1.1 christos /*
383 1.1 christos Read bytes from the current file (opened by unzOpenCurrentFile)
384 1.1 christos buf contain buffer where data must be copied
385 1.1 christos len the size of buf.
386 1.1 christos
387 1.1 christos return the number of byte copied if somes bytes are copied
388 1.1 christos return 0 if the end of file was reached
389 1.1 christos return <0 with error code if there is an error
390 1.1 christos (UNZ_ERRNO for IO error, or zLib error for uncompress error)
391 1.1 christos */
392 1.1 christos
393 1.1 christos extern z_off_t ZEXPORT unztell OF((unzFile file));
394 1.1.1.2 christos
395 1.1.1.2 christos extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
396 1.1 christos /*
397 1.1 christos Give the current position in uncompressed data
398 1.1 christos */
399 1.1 christos
400 1.1 christos extern int ZEXPORT unzeof OF((unzFile file));
401 1.1 christos /*
402 1.1 christos return 1 if the end of file was reached, 0 elsewhere
403 1.1 christos */
404 1.1 christos
405 1.1 christos extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
406 1.1 christos voidp buf,
407 1.1 christos unsigned len));
408 1.1 christos /*
409 1.1 christos Read extra field from the current file (opened by unzOpenCurrentFile)
410 1.1 christos This is the local-header version of the extra field (sometimes, there is
411 1.1 christos more info in the local-header version than in the central-header)
412 1.1 christos
413 1.1 christos if buf==NULL, it return the size of the local extra field
414 1.1 christos
415 1.1 christos if buf!=NULL, len is the size of the buffer, the extra header is copied in
416 1.1 christos buf.
417 1.1 christos the return value is the number of bytes copied in buf, or (if <0)
418 1.1 christos the error code
419 1.1 christos */
420 1.1 christos
421 1.1 christos /***************************************************************************/
422 1.1 christos
423 1.1 christos /* Get the current file offset */
424 1.1.1.2 christos extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
425 1.1 christos extern uLong ZEXPORT unzGetOffset (unzFile file);
426 1.1 christos
427 1.1 christos /* Set the current file offset */
428 1.1.1.2 christos extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
429 1.1 christos extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
430 1.1 christos
431 1.1 christos
432 1.1 christos
433 1.1 christos #ifdef __cplusplus
434 1.1 christos }
435 1.1 christos #endif
436 1.1 christos
437 1.1.1.2 christos #endif /* _unz64_H */
438