fw4spl
zip.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 /* zip.h -- IO on .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 for Zip64 support
14  Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
15 
16  For more info read MiniZip_info.txt
17 
18  ---------------------------------------------------------------------------
19 
20  Condition of use and distribution are the same than zlib :
21 
22  This software is provided 'as-is', without any express or implied
23  warranty. In no event will the authors be held liable for any damages
24  arising from the use of this software.
25 
26  Permission is granted to anyone to use this software for any purpose,
27  including commercial applications, and to alter it and redistribute it
28  freely, subject to the following restrictions:
29 
30  1. The origin of this software must not be misrepresented; you must not
31  claim that you wrote the original software. If you use this software
32  in a product, an acknowledgment in the product documentation would be
33  appreciated but is not required.
34  2. Altered source versions must be plainly marked as such, and must not be
35  misrepresented as being the original software.
36  3. This notice may not be removed or altered from any source distribution.
37 
38  ---------------------------------------------------------------------------
39 
40  Changes
41 
42  See header of zip.h
43 
44  */
45 
46 #ifndef __MINIZIP_ZIP_H__
47 #define __MINIZIP_ZIP_H__
48 
49 #include "minizip/export.h"
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 //#define HAVE_BZIP2
56 
57 #ifndef _ZLIB_H
58 #include <zlib.h>
59 #endif
60 
61 #ifndef _ZLIBIOAPI_H
62 #include "minizip/ioapi.h"
63 #endif
64 
65 #ifdef HAVE_BZIP2
66 #include <bzlib.h>
67 #endif
68 
69 #define Z_BZIP2ED 12
70 
71 #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
72 /* like the STRICT of WIN32, we define a pointer that cannot be converted
73  from (void*) without cast */
74 typedef struct TagzipFile__ { int unused; } zipFile__;
75 typedef zipFile__ *zipFile;
76 #else
77 typedef voidp zipFile;
78 #endif
79 
80 #define ZIP_OK (0)
81 #define ZIP_EOF (0)
82 #define ZIP_ERRNO (Z_ERRNO)
83 #define ZIP_PARAMERROR (-102)
84 #define ZIP_BADZIPFILE (-103)
85 #define ZIP_INTERNALERROR (-104)
86 
87 #ifndef DEF_MEM_LEVEL
88 # if MAX_MEM_LEVEL >= 8
89 # define DEF_MEM_LEVEL 8
90 # else
91 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
92 # endif
93 #endif
94 /* default memLevel */
95 
96 /* tm_zip contain date/time info */
97 typedef struct tm_zip_s
98 {
99  uInt tm_sec; /* seconds after the minute - [0,59] */
100  uInt tm_min; /* minutes after the hour - [0,59] */
101  uInt tm_hour; /* hours since midnight - [0,23] */
102  uInt tm_mday; /* day of the month - [1,31] */
103  uInt tm_mon; /* months since January - [0,11] */
104  uInt tm_year; /* years - [1980..2044] */
105 } tm_zip;
106 
107 typedef struct
108 {
109  tm_zip tmz_date; /* date in understandable format */
110  uLong dosDate; /* if dos_date == 0, tmu_date is used */
111 /* uLong flag; */ /* general purpose bit flag 2 bytes */
112 
113  uLong internal_fa; /* internal file attributes 2 bytes */
114  uLong external_fa; /* external file attributes 4 bytes */
115 } zip_fileinfo;
116 
117 typedef const char* zipcharpc;
118 
119 
120 #define APPEND_STATUS_CREATE (0)
121 #define APPEND_STATUS_CREATEAFTER (1)
122 #define APPEND_STATUS_ADDINZIP (2)
123 
124 extern MINIZIP_API zipFile zipOpen OF((const char *pathname, int append));
125 extern MINIZIP_API zipFile zipOpen64 OF((const void *pathname, int append));
126 /*
127  Create a zipfile.
128  pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
129  an Unix computer "zlib/zlib113.zip".
130  if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
131  will be created at the end of the file.
132  (useful if the file contain a self extractor code)
133  if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
134  add files in existing zip (be sure you don't add file that doesn't exist)
135  If the zipfile cannot be opened, the return value is NULL.
136  Else, the return value is a zipFile Handle, usable with other function
137  of this zip package.
138  */
139 
140 /* Note : there is no delete function into a zipfile.
141  If you want delete file into a zipfile, you must open a zipfile, and create another
142  Of couse, you can use RAW reading and writing to copy the file you did not want delte
143  */
144 
145 extern MINIZIP_API zipFile zipOpen2 OF((const char *pathname,
146  int append,
147  zipcharpc* globalcomment,
148  zlib_filefunc_def* pzlib_filefunc_def));
149 
150 extern MINIZIP_API zipFile zipOpen2_64 OF((const void *pathname,
151  int append,
152  zipcharpc* globalcomment,
153  zlib_filefunc64_def* pzlib_filefunc_def));
154 
155 extern MINIZIP_API int zipOpenNewFileInZip OF((zipFile file,
156  const char* filename,
157  const zip_fileinfo* zipfi,
158  const void* extrafield_local,
159  uInt size_extrafield_local,
160  const void* extrafield_global,
161  uInt size_extrafield_global,
162  const char* comment,
163  int method,
164  int level));
165 
166 extern MINIZIP_API int zipOpenNewFileInZip64 OF((zipFile file,
167  const char* filename,
168  const zip_fileinfo* zipfi,
169  const void* extrafield_local,
170  uInt size_extrafield_local,
171  const void* extrafield_global,
172  uInt size_extrafield_global,
173  const char* comment,
174  int method,
175  int level,
176  int zip64));
177 
178 /*
179  Open a file in the ZIP for writing.
180  filename : the filename in zip (if NULL, '-' without quote will be used
181  * zipfi contain supplemental information
182  if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
183  contains the extrafield data the the local header
184  if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
185  contains the extrafield data the the local header
186  if comment != NULL, comment contain the comment string
187  method contain the compression method (0 for store, Z_DEFLATED for deflate)
188  level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
189  zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
190  this MUST be '1' if the uncompressed size is >= 0xffffffff.
191 
192  */
193 
194 
195 extern MINIZIP_API int zipOpenNewFileInZip2 OF((zipFile file,
196  const char* filename,
197  const zip_fileinfo* zipfi,
198  const void* extrafield_local,
199  uInt size_extrafield_local,
200  const void* extrafield_global,
201  uInt size_extrafield_global,
202  const char* comment,
203  int method,
204  int level,
205  int raw));
206 
207 
208 extern MINIZIP_API int zipOpenNewFileInZip2_64 OF((zipFile file,
209  const char* filename,
210  const zip_fileinfo* zipfi,
211  const void* extrafield_local,
212  uInt size_extrafield_local,
213  const void* extrafield_global,
214  uInt size_extrafield_global,
215  const char* comment,
216  int method,
217  int level,
218  int raw,
219  int zip64));
220 /*
221  Same than zipOpenNewFileInZip, except if raw=1, we write raw file
222  */
223 
224 extern MINIZIP_API int zipOpenNewFileInZip3 OF((zipFile file,
225  const char* filename,
226  const zip_fileinfo* zipfi,
227  const void* extrafield_local,
228  uInt size_extrafield_local,
229  const void* extrafield_global,
230  uInt size_extrafield_global,
231  const char* comment,
232  int method,
233  int level,
234  int raw,
235  int windowBits,
236  int memLevel,
237  int strategy,
238  const char* password,
239  uLong crcForCrypting));
240 
241 extern MINIZIP_API int zipOpenNewFileInZip3_64 OF((zipFile file,
242  const char* filename,
243  const zip_fileinfo* zipfi,
244  const void* extrafield_local,
245  uInt size_extrafield_local,
246  const void* extrafield_global,
247  uInt size_extrafield_global,
248  const char* comment,
249  int method,
250  int level,
251  int raw,
252  int windowBits,
253  int memLevel,
254  int strategy,
255  const char* password,
256  uLong crcForCrypting,
257  int zip64
258  ));
259 
260 /*
261  Same than zipOpenNewFileInZip2, except
262  windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
263  password : crypting password (NULL for no crypting)
264  crcForCrypting : crc of file to compress (needed for crypting)
265  */
266 
267 extern MINIZIP_API int zipOpenNewFileInZip4 OF((zipFile file,
268  const char* filename,
269  const zip_fileinfo* zipfi,
270  const void* extrafield_local,
271  uInt size_extrafield_local,
272  const void* extrafield_global,
273  uInt size_extrafield_global,
274  const char* comment,
275  int method,
276  int level,
277  int raw,
278  int windowBits,
279  int memLevel,
280  int strategy,
281  const char* password,
282  uLong crcForCrypting,
283  uLong versionMadeBy,
284  uLong flagBase
285  ));
286 
287 
288 extern MINIZIP_API int zipOpenNewFileInZip4_64 OF((zipFile file,
289  const char* filename,
290  const zip_fileinfo* zipfi,
291  const void* extrafield_local,
292  uInt size_extrafield_local,
293  const void* extrafield_global,
294  uInt size_extrafield_global,
295  const char* comment,
296  int method,
297  int level,
298  int raw,
299  int windowBits,
300  int memLevel,
301  int strategy,
302  const char* password,
303  uLong crcForCrypting,
304  uLong versionMadeBy,
305  uLong flagBase,
306  int zip64
307  ));
308 /*
309  Same than zipOpenNewFileInZip4, except
310  versionMadeBy : value for Version made by field
311  flag : value for flag field (compression level info will be added)
312  */
313 
314 
315 extern MINIZIP_API int zipWriteInFileInZip OF((zipFile file,
316  const void* buf,
317  unsigned len));
318 /*
319  Write data in the zipfile
320  */
321 
322 extern MINIZIP_API int zipCloseFileInZip OF((zipFile file));
323 /*
324  Close the current file in the zipfile
325  */
326 
327 extern MINIZIP_API int zipCloseFileInZipRaw OF((zipFile file,
328  uLong uncompressed_size,
329  uLong crc32));
330 
331 extern MINIZIP_API int zipCloseFileInZipRaw64 OF((zipFile file,
332  ZPOS64_T uncompressed_size,
333  uLong crc32));
334 
335 /*
336  Close the current file in the zipfile, for file opened with
337  parameter raw=1 in zipOpenNewFileInZip2
338  uncompressed_size and crc32 are value for the uncompressed size
339  */
340 
341 extern MINIZIP_API int zipClose OF((zipFile file,
342  const char* global_comment));
343 /*
344  Close the zipfile
345  */
346 
347 
348 extern MINIZIP_API int zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
349 /*
350  zipRemoveExtraInfoBlock - Added by Mathias Svensson
351 
352  Remove extra information block from a extra information data for the local file header or central directory header
353 
354  It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
355 
356  0x0001 is the signature header for the ZIP64 extra information blocks
357 
358  usage.
359  Remove ZIP64 Extra information from a central director extra field data
360  zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
361 
362  Remove ZIP64 Extra information from a Local File Header extra field data
363  zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
364  */
365 
366 #ifdef __cplusplus
367 }
368 #endif
369 
370 #endif //__MINIZIP_ZIP_H__
Definition: zip.h:97