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