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