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