Stroika Library 3.0d20
 
Loading...
Searching...
No Matches
Private_minizip_.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include <limits>
7
8#if qStroika_HasComponent_zlib
9#ifdef HAVE_BZIP2
10#include "bzlib.h"
11#endif
12#include <zlib.h>
13#ifdef HAVE_MINIZIP64_CONF_H
14#include "mz64conf.h"
15#endif
16#endif
17
19
20#if qStroika_HasComponent_zlib
21namespace Stroika::Foundation::DataExchange::Archive::Zip::PrivateMinizip_ {
22
23 /*
24 * Part of Stroika IMPLEMENTATION - but not included in any Stroika headers.
25 *
26 * NOTE/CREDIT:
27 * This code originally cribbed from ZLib (http://www.zlib.net/) 1.2.8 contrib/minizip
28 *
29 Version 1.1, February 14h, 2010
30 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
31
32 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
33
34 Modifications for Zip64 support
35 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
36
37 For more info read MiniZip_info.txt
38
39 ---------------------------------------------------------------------------
40
41 Condition of use and distribution are the same than zlib :
42
43 This software is provided 'as-is', without any express or implied
44 warranty. In no event will the authors be held liable for any damages
45 arising from the use of this software.
46
47 Permission is granted to anyone to use this software for any purpose,
48 including commercial applications, and to alter it and redistribute it
49 freely, subject to the following restrictions:
50
51 1. The origin of this software must not be misrepresented; you must not
52 claim that you wrote the original software. If you use this software
53 in a product, an acknowledgment in the product documentation would be
54 appreciated but is not required.
55 2. Altered source versions must be plainly marked as such, and must not be
56 misrepresented as being the original software.
57 3. This notice may not be removed or altered from any source distribution.
58....
59 Version 1.1, February 14h, 2010
60 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
61
62 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
63
64 Modifications of Unzip for Zip64
65 Copyright (C) 2007-2008 Even Rouault
66
67 Modifications for Zip64 support on both zip and unzip
68 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
69
70 For more info read MiniZip_info.txt
71
72 ---------------------------------------------------------------------------------
73
74 Condition of use and distribution are the same than zlib :
75
76 This software is provided 'as-is', without any express or implied
77 warranty. In no event will the authors be held liable for any damages
78 arising from the use of this software.
79
80 Permission is granted to anyone to use this software for any purpose,
81 including commercial applications, and to alter it and redistribute it
82 freely, subject to the following restrictions:
83
84 1. The origin of this software must not be misrepresented; you must not
85 claim that you wrote the original software. If you use this software
86 in a product, an acknowledgment in the product documentation would be
87 appreciated but is not required.
88 2. Altered source versions must be plainly marked as such, and must not be
89 misrepresented as being the original software.
90 3. This notice may not be removed or altered from any source distribution.
91....
92 Copyright (C) 1998-2005 Gilles Vollant
93
94 This code is a modified version of crypting code in Infozip distribution
95
96 The encryption/decryption parts of this source code (as opposed to the
97 non-echoing password parts) were originally written in Europe. The
98 whole source package can be freely distributed, including from the USA.
99 (Prior to January 2000, re-export from the US was a violation of US law.)
100
101 This encryption code is a direct transcription of the algorithm from
102 Roger Schlafly, described by Phil Katz in the file appnote.txt. This
103 file (appnote.txt) is distributed with the PKZIP program (even in the
104 version without encryption capabilities).
105
106 If you don't need crypting in your application, just define symbols
107 NOCRYPT and NOUNCRYPT.
108
109 This code support the "Traditional PKWARE Encryption".
110
111 The new AES encryption added on Zip format by Winzip (see the page
112 http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong
113 Encryption is not supported.
114....
115 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
116
117 Modifications of Unzip for Zip64
118 Copyright (C) 2007-2008 Even Rouault
119
120 Modifications for Zip64 support on both zip and unzip
121 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
122
123 For more info read MiniZip_info.txt
124 ------------------------------------------------------------------------------------
125 Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
126 compatibility with older software. The following is from the original crypt.c.
127 Code woven in by Terry Thorsen 1/2003.
128
129 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
130
131 See the accompanying file LICENSE, version 2000-Apr-09 or later
132 (the contents of which are also included in zip.h) for terms of use.
133 If, for some reason, all these files are missing, the Info-ZIP license
134 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
135
136 crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
137
138 The encryption/decryption parts of this source code (as opposed to the
139 non-echoing password parts) were originally written in Europe. The
140 whole source package can be freely distributed, including from the USA.
141 (Prior to January 2000, re-export from the US was a violation of US law.)
142
143 This encryption code is a direct transcription of the algorithm from
144 Roger Schlafly, described by Phil Katz in the file appnote.txt. This
145 file (appnote.txt) is distributed with the PKZIP program (even in the
146 version without encryption capabilities).
147...
148 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
149
150 Modifications for Zip64 support
151 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
152*/
153
154 using namespace std;
155
156 constexpr uint32_t MAXU32 = numeric_limits<uint32_t>::max ();
157
158///// START OF CRYPT.h
159#define CRC32(c, b) ((*(pcrc_32_tab + (((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
160
161 // Return the next byte in the pseudo-random sequence
162 inline int decrypt_byte (unsigned long* pkeys, [[maybe_unused]] const z_crc_t* pcrc_32_tab)
163 {
164 unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
165 * unpredictable manner on 16-bit systems; not a problem
166 * with any known compiler so far, though */
167 temp = ((unsigned)(*(pkeys + 2)) & 0xffff) | 2;
168 return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
169 }
170
171 // Update the encryption keys with the next byte of plain text
172 inline int update_keys (unsigned long* pkeys, const z_crc_t* pcrc_32_tab, int c)
173 {
174 (*(pkeys + 0)) = CRC32 ((*(pkeys + 0)), c);
175 (*(pkeys + 1)) += (*(pkeys + 0)) & 0xff;
176 (*(pkeys + 1)) = (*(pkeys + 1)) * 134775813L + 1;
177 {
178 int keyshift = (int)((*(pkeys + 1)) >> 24);
179 (*(pkeys + 2)) = CRC32 ((*(pkeys + 2)), keyshift);
180 }
181 return c;
182 }
183
184 // Initialize the encryption keys and the random header according to the given password.
185 inline void init_keys (const char* passwd, unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
186 {
187 *(pkeys + 0) = 305419896L;
188 *(pkeys + 1) = 591751049L;
189 *(pkeys + 2) = 878082192L;
190 while (*passwd != '\0') {
191 update_keys (pkeys, pcrc_32_tab, (int)*passwd);
192 passwd++;
193 }
194 }
195
196#define zdecode(pkeys, pcrc_32_tab, c) (update_keys (pkeys, pcrc_32_tab, c ^= decrypt_byte (pkeys, pcrc_32_tab)))
197
198#define zencode(pkeys, pcrc_32_tab, c, t) (t = decrypt_byte (pkeys, pcrc_32_tab), update_keys (pkeys, pcrc_32_tab, c), t ^ (c))
199
200#define RAND_HEAD_LEN 12
201
202 /* "last resort" source for second part of crypt seed pattern */
203 constexpr unsigned int ZCR_SEED2 = 3141592654UL; /* use PI as default pattern */
204
205 inline int crypthead (const char* passwd, /* password string */
206 unsigned char* buf, /* where to write header */
207 int bufSize, unsigned long* pkeys, const z_crc_t* pcrc_32_tab, unsigned long crcForCrypting)
208 {
209 int n; /* index in random header */
210 int t; /* temporary */
211 int c; /* random byte */
212 unsigned char header[RAND_HEAD_LEN - 2]; /* random header */
213 static unsigned calls = 0; /* ensure different random header each time */
214
215 if (bufSize < RAND_HEAD_LEN)
216 return 0;
217
218 /* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
219 * output of rand() to get less predictability, since rand() is
220 * often poorly implemented.
221 */
222 if (++calls == 1) {
223 srand ((unsigned)(time (NULL) ^ ZCR_SEED2));
224 }
225 init_keys (passwd, pkeys, pcrc_32_tab);
226 for (n = 0; n < RAND_HEAD_LEN - 2; n++) {
227 c = (rand () >> 7) & 0xff;
228 header[n] = (unsigned char)zencode (pkeys, pcrc_32_tab, c, t);
229 }
230 /* Encrypt random header (last two bytes is high word of crc) */
231 init_keys (passwd, pkeys, pcrc_32_tab);
232 for (n = 0; n < RAND_HEAD_LEN - 2; n++) {
233 buf[n] = (unsigned char)zencode (pkeys, pcrc_32_tab, header[n], t);
234 }
235 buf[n++] = (unsigned char)zencode (pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
236 buf[n++] = (unsigned char)zencode (pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
237 return n;
238 }
239 ///////////// END OF CRYPT.h //////////////////
240
241 ///// START OF ioapi.h////////////////////
242
243 typedef uint64_t ZPOS64_T;
244
245#define ZLIB_FILEFUNC_SEEK_CUR (1)
246#define ZLIB_FILEFUNC_SEEK_END (2)
247#define ZLIB_FILEFUNC_SEEK_SET (0)
248
249#define ZLIB_FILEFUNC_MODE_READ (1)
250#define ZLIB_FILEFUNC_MODE_WRITE (2)
251#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
252
253#define ZLIB_FILEFUNC_MODE_EXISTING (4)
254#define ZLIB_FILEFUNC_MODE_CREATE (8)
255
256 typedef voidpf (*open_file_func) (voidpf opaque, const char* filename, int mode);
257 typedef uLong (*read_file_func) (voidpf opaque, voidpf stream, void* buf, uLong size);
258 typedef uLong (*write_file_func) (voidpf opaque, voidpf stream, const void* buf, uLong size);
259 typedef int (*close_file_func) (voidpf opaque, voidpf stream);
260 typedef int (*testerror_file_func) (voidpf opaque, voidpf stream);
261
262 typedef long (*tell_file_func) (voidpf opaque, voidpf stream);
263 typedef long (*seek_file_func) (voidpf opaque, voidpf stream, uLong offset, int origin);
264
265 /* here is the "old" 32 bits structure structure */
266 struct zlib_filefunc_def {
267 open_file_func zopen_file;
268 read_file_func zread_file;
269 write_file_func zwrite_file;
270 tell_file_func ztell_file;
271 seek_file_func zseek_file;
272 close_file_func zclose_file;
273 testerror_file_func zerror_file;
274 voidpf opaque;
275 };
276
277 typedef ZPOS64_T (*tell64_file_func) (voidpf opaque, voidpf stream);
278 typedef long (*seek64_file_func) (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin);
279 typedef voidpf (*open64_file_func) (voidpf opaque, const void* filename, int mode);
280
281 struct zlib_filefunc64_def {
282 open64_file_func zopen64_file;
283 read_file_func zread_file;
284 write_file_func zwrite_file;
285 tell64_file_func ztell64_file;
286 seek64_file_func zseek64_file;
287 close_file_func zclose_file;
288 testerror_file_func zerror_file;
289 voidpf opaque;
290 };
291
292 /* now internal definition, only for zip.c and unzip.h */
293 struct zlib_filefunc64_32_def {
294 zlib_filefunc64_def zfile_func64;
295 open_file_func zopen32_file;
296 tell_file_func ztell32_file;
297 seek_file_func zseek32_file;
298 };
299
300#define ZREAD64(filefunc, filestream, buf, size) \
301 ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque, filestream, buf, size))
302#define ZWRITE64(filefunc, filestream, buf, size) \
303 ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque, filestream, buf, size))
304#define ZCLOSE64(filefunc, filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque, filestream))
305#define ZERROR64(filefunc, filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque, filestream))
306
307 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc, const void* filename, int mode);
308 long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, ZPOS64_T offset, int origin);
309 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc, voidpf filestream);
310
311 void fill_zlib_filefunc64_32_def_from_filefunc32 (zlib_filefunc64_32_def* p_filefunc64_32, const zlib_filefunc_def* p_filefunc32);
312
313#define ZOPEN64(filefunc, filename, mode) (call_zopen64 ((&(filefunc)), (filename), (mode)))
314#define ZTELL64(filefunc, filestream) (call_ztell64 ((&(filefunc)), (filestream)))
315#define ZSEEK64(filefunc, filestream, pos, mode) (call_zseek64 ((&(filefunc)), (filestream), (pos), (mode)))
316 /////////////////////// END OF IO.h.////////////////////////////////////
317
318 /////////////////////////// START OF UNZIP.h ////////////////////////////////////
319
320#define Z_BZIP2ED 12
321
322#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
323 /* like the STRICT of WIN32, we define a pointer that cannot be converted
324 from (void*) without cast */
325 typedef struct TagunzFile__ {
326 int unused;
327 } unzFile__;
328 typedef unzFile__* unzFile;
329#else
330 typedef voidp unzFile;
331#endif
332
333#define UNZ_OK (0)
334#define UNZ_END_OF_LIST_OF_FILE (-100)
335#define UNZ_ERRNO (Z_ERRNO)
336#define UNZ_EOF (0)
337#define UNZ_PARAMERROR (-102)
338#define UNZ_BADZIPFILE (-103)
339#define UNZ_INTERNALERROR (-104)
340#define UNZ_CRCERROR (-105)
341
342 /* tm_unz contain date/time info */
343 struct tm_unz {
344 uInt tm_sec; /* seconds after the minute - [0,59] */
345 uInt tm_min; /* minutes after the hour - [0,59] */
346 uInt tm_hour; /* hours since midnight - [0,23] */
347 uInt tm_mday; /* day of the month - [1,31] */
348 uInt tm_mon; /* months since January - [0,11] */
349 uInt tm_year; /* years - [1980..2044] */
350 };
351
352 /* unz_global_info structure contain global data about the ZIPfile
353 These data comes from the end of central dir */
354 struct unz_global_info64 {
355 ZPOS64_T number_entry; /* total number of entries in
356 the central dir on this disk */
357 uLong size_comment; /* size of the global comment of the zipfile */
358 };
359
360 struct unz_global_info {
361 uLong number_entry; /* total number of entries in
362 the central dir on this disk */
363 uLong size_comment; /* size of the global comment of the zipfile */
364 };
365
366 /* unz_file_info contain information about a file in the zipfile */
367 struct unz_file_info64 {
368 uLong version; /* version made by 2 bytes */
369 uLong version_needed; /* version needed to extract 2 bytes */
370 uLong flag; /* general purpose bit flag 2 bytes */
371 uLong compression_method; /* compression method 2 bytes */
372 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
373 uLong crc; /* crc-32 4 bytes */
374 ZPOS64_T compressed_size; /* compressed size 8 bytes */
375 ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
376 uLong size_filename; /* filename length 2 bytes */
377 uLong size_file_extra; /* extra field length 2 bytes */
378 uLong size_file_comment; /* file comment length 2 bytes */
379
380 uLong disk_num_start; /* disk number start 2 bytes */
381 uLong internal_fa; /* internal file attributes 2 bytes */
382 uLong external_fa; /* external file attributes 4 bytes */
383
384 tm_unz tmu_date;
385 };
386
387 struct unz_file_info {
388 uLong version; /* version made by 2 bytes */
389 uLong version_needed; /* version needed to extract 2 bytes */
390 uLong flag; /* general purpose bit flag 2 bytes */
391 uLong compression_method; /* compression method 2 bytes */
392 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
393 uLong crc; /* crc-32 4 bytes */
394 uLong compressed_size; /* compressed size 4 bytes */
395 uLong uncompressed_size; /* uncompressed size 4 bytes */
396 uLong size_filename; /* filename length 2 bytes */
397 uLong size_file_extra; /* extra field length 2 bytes */
398 uLong size_file_comment; /* file comment length 2 bytes */
399
400 uLong disk_num_start; /* disk number start 2 bytes */
401 uLong internal_fa; /* internal file attributes 2 bytes */
402 uLong external_fa; /* external file attributes 4 bytes */
403
404 tm_unz tmu_date;
405 };
406
407 int unzStringFileNameCompare (const char* fileName1, const char* fileName2, int iCaseSensitivity);
408 /*
409 Compare two filename (fileName1,fileName2).
410 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
411 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
412 or strcasecmp)
413 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
414 (like 1 on Unix, 2 on Windows)
415 */
416
417 /*
418 Open a Zip file. path contain the full pathname (by example,
419 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
420 "zlib/zlib113.zip".
421 If the zipfile cannot be opened (file don't exist or in not valid), the
422 return value is NULL.
423 Else, the return value is a unzFile Handle, usable with other function
424 of this unzip package.
425 the "64" function take a const void* pointer, because the path is just the
426 value passed to the open64_file_func callback.
427 Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
428 is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
429 does not describe the reality
430 */
431 unzFile unzOpen (const char* path);
432 unzFile unzOpen64 (const void* path);
433
434 /*
435 Open a Zip file, like unzOpen, but provide a set of file low level API
436 for read/write the zip file (see ioapi.h)
437 */
438 unzFile unzOpen2 (const char* path, zlib_filefunc_def* pzlib_filefunc_def);
439
440 /*
441 Open a Zip file, like unz64Open, but provide a set of file low level API
442 for read/write the zip file (see ioapi.h)
443 */
444 unzFile unzOpen2_64 (const void* path, zlib_filefunc64_def* pzlib_filefunc_def);
445
446 int unzClose (unzFile file);
447 /*
448 Close a ZipFile opened with unzOpen.
449 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
450 these files MUST be closed with unzCloseCurrentFile before call unzClose.
451 return UNZ_OK if there is no problem. */
452
453 int unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info);
454
455 /*
456 Write info about the ZipFile in the *pglobal_info structure.
457 No preparation of the structure is needed
458 return UNZ_OK if there is no problem. */
459 int unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info);
460
461 /*
462 Get the global comment string of the ZipFile, in the szComment buffer.
463 uSizeBuf is the size of the szComment buffer.
464 return the number of byte copied or an error code <0
465 */
466 int unzGetGlobalComment (unzFile file, char* szComment, uLong uSizeBuf);
467
468 /***************************************************************************/
469 /* Unzip package allow you browse the directory of the zipfile */
470
471 /*
472 Set the current file of the zipfile to the first file.
473 return UNZ_OK if there is no problem
474 */
475 int unzGoToFirstFile (unzFile file);
476
477 /*
478 Set the current file of the zipfile to the next file.
479 return UNZ_OK if there is no problem
480 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
481 */
482 int unzGoToNextFile_ (unzFile file);
483
484 /*
485 Try locate the file szFileName in the zipfile.
486 For the iCaseSensitivity signification, see unzStringFileNameCompare
487
488 return value :
489 UNZ_OK if the file is found. It becomes the current file.
490 UNZ_END_OF_LIST_OF_FILE if the file is not found
491 */
492 int unzLocateFile_ (unzFile file, const char* szFileName, int iCaseSensitivity);
493
494 /* ****************************************** */
495 /* Ryan supplied functions */
496 /* unz_file_info contain information about a file in the zipfile */
497 struct unz_file_pos {
498 uLong pos_in_zip_directory; /* offset in zip file directory */
499 uLong num_of_file; /* # of file */
500 };
501
502 int unzGetFilePos (unzFile file, unz_file_pos* file_pos);
503
504 int unzGoToFilePos (unzFile file, unz_file_pos* file_pos);
505
506 struct unz64_file_pos {
507 ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
508 ZPOS64_T num_of_file; /* # of file */
509 };
510
511 int unzGetFilePos64 (unzFile file, unz64_file_pos* file_pos);
512
513 int unzGoToFilePos64 (unzFile file, const unz64_file_pos* file_pos);
514
515 /* ****************************************** */
516 int unzGetCurrentFileInfo64 (unzFile file, unz_file_info64* pfile_info, char* szFileName, uLong fileNameBufferSize, void* extraField,
517 uLong extraFieldBufferSize, char* szComment, uLong commentBufferSize);
518
519 int unzGetCurrentFileInfo (unzFile file, unz_file_info* pfile_info, char* szFileName, uLong fileNameBufferSize, void* extraField,
520 uLong extraFieldBufferSize, char* szComment, uLong commentBufferSize);
521 /*
522 Get Info about the current file
523 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
524 the current file
525 if szFileName!=NULL, the filemane string will be copied in szFileName
526 (fileNameBufferSize is the size of the buffer)
527 if extraField!=NULL, the extra field information will be copied in extraField
528 (extraFieldBufferSize is the size of the buffer).
529 This is the Central-header version of the extra field
530 if szComment!=NULL, the comment string of the file will be copied in szComment
531 (commentBufferSize is the size of the buffer)
532 */
533
534 ZPOS64_T unzGetCurrentFileZStreamPos64 (unzFile file);
535
536 /***************************************************************************/
537 /* for reading the content of the current zipfile, you can open it, read data
538 from it, and close it (you can close it before reading all the file)
539 */
540 /*
541 Open for reading data the current file in the zipfile.
542 If there is no error, the return value is UNZ_OK.
543 */
544 int unzOpenCurrentFile (unzFile file);
545
546 /*
547 Open for reading data the current file in the zipfile.
548 password is a crypting password
549 If there is no error, the return value is UNZ_OK.
550 */
551 int unzOpenCurrentFilePassword (unzFile file, const char* password);
552
553 /*
554 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
555 if raw==1
556 *method will receive method of compression, *level will receive level of
557 compression
558 note : you can set level parameter as NULL (if you did not want known level,
559 but you CANNOT set method parameter as NULL
560 */
561 int unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw);
562
563 /*
564 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
565 if raw==1
566 *method will receive method of compression, *level will receive level of
567 compression
568 note : you can set level parameter as NULL (if you did not want known level,
569 but you CANNOT set method parameter as NULL
570 */
571 int unzOpenCurrentFile3_ (unzFile file, int* method, int* level, int raw, const char* password);
572
573 /*
574 Close the file in zip opened with unzOpenCurrentFile
575 Return UNZ_CRCERROR if all the file was read but the CRC is not good
576 */
577 int unzCloseCurrentFile_ (unzFile file);
578
579 /*
580 Read bytes from the current file (opened by unzOpenCurrentFile)
581 buf contain buffer where data must be copied
582 len the size of buf.
583
584 return the number of byte copied if some bytes are copied
585 return 0 if the end of file was reached
586 return <0 with error code if there is an error
587 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
588 */
589 int unzReadCurrentFile_ (unzFile file, voidp buf, unsigned len);
590
591 z_off_t unztell (unzFile file);
592
593 ZPOS64_T unztell64 (unzFile file);
594 /*
595 Give the current position in uncompressed data
596 */
597
598 /*
599 return 1 if the end of file was reached, 0 elsewhere
600 */
601 int unzeof (unzFile file);
602
603 /*
604 Read extra field from the current file (opened by unzOpenCurrentFile)
605 This is the local-header version of the extra field (sometimes, there is
606 more info in the local-header version than in the central-header)
607
608 if buf==NULL, it return the size of the local extra field
609
610 if buf!=NULL, len is the size of the buffer, the extra header is copied in
611 buf.
612 the return value is the number of bytes copied in buf, or (if <0)
613 the error code
614 */
615 int unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len);
616
617 /***************************************************************************/
618
619 /* Get the current file offset */
620 ZPOS64_T unzGetOffset64 (unzFile file);
621 uLong unzGetOffset (unzFile file);
622
623 /* Set the current file offset */
624 int unzSetOffset64 (unzFile file, ZPOS64_T pos);
625 int unzSetOffset (unzFile file, uLong pos);
626 //// END OF unzip.h//////////////////////////////////////////////////////////////
627
628 //// FROM zip.h
629#define Z_BZIP2ED 12
630
631#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
632 /* like the STRICT of WIN32, we define a pointer that cannot be converted
633 from (void*) without cast */
634 typedef struct TagzipFile__ {
635 int unused;
636 } zipFile__;
637 typedef zipFile__* zipFile;
638#else
639 typedef voidp zipFile;
640#endif
641
642#define ZIP_OK (0)
643#define ZIP_EOF (0)
644#define ZIP_ERRNO (Z_ERRNO)
645#define ZIP_PARAMERROR (-102)
646#define ZIP_BADZIPFILE (-103)
647#define ZIP_INTERNALERROR (-104)
648
649#ifndef DEF_MEM_LEVEL
650#if MAX_MEM_LEVEL >= 8
651#define DEF_MEM_LEVEL 8
652#else
653#define DEF_MEM_LEVEL MAX_MEM_LEVEL
654#endif
655#endif
656 /* default memLevel */
657
658 /* tm_zip contain date/time info */
659 typedef struct tm_zip_s {
660 int tm_sec; /* seconds after the minute - [0,59] */
661 int tm_min; /* minutes after the hour - [0,59] */
662 int tm_hour; /* hours since midnight - [0,23] */
663 int tm_mday; /* day of the month - [1,31] */
664 int tm_mon; /* months since January - [0,11] */
665 int tm_year; /* years - [1980..2044] */
666 } tm_zip;
667
668 typedef struct {
669 tm_zip tmz_date; /* date in understandable format */
670 uLong dosDate; /* if dos_date == 0, tmu_date is used */
671 /* uLong flag; */ /* general purpose bit flag 2 bytes */
672
673 uLong internal_fa; /* internal file attributes 2 bytes */
674 uLong external_fa; /* external file attributes 4 bytes */
675 } zip_fileinfo;
676
677 typedef const char* zipcharpc;
678
679#define APPEND_STATUS_CREATE (0)
680#define APPEND_STATUS_CREATEAFTER (1)
681#define APPEND_STATUS_ADDINZIP (2)
682
683 extern zipFile ZEXPORT zipOpen (const char* pathname, int append);
684 extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append);
685 /*
686 Create a zipfile.
687 pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
688 an Unix computer "zlib/zlib113.zip".
689 if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
690 will be created at the end of the file.
691 (useful if the file contain a self extractor code)
692 if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
693 add files in existing zip (be sure you don't add file that doesn't exist)
694 If the zipfile cannot be opened, the return value is NULL.
695 Else, the return value is a zipFile Handle, usable with other function
696 of this zip package.
697*/
698
699 /* Note : there is no delete function into a zipfile.
700 If you want delete file into a zipfile, you must open a zipfile, and create another
701 Of course, you can use RAW reading and writing to copy the file you did not want delete
702*/
703
704 extern zipFile ZEXPORT zipOpen2 (const char* pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc_def);
705
706 extern zipFile ZEXPORT zipOpen2_64 (const void* pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def);
707
708 extern zipFile ZEXPORT zipOpen3 (const void* pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def);
709
710 extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local,
711 uInt size_extrafield_local, const void* extrafield_global, uInt size_extrafield_global,
712 const char* comment, int method, int level);
713
714 extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local,
715 uInt size_extrafield_local, const void* extrafield_global, uInt size_extrafield_global,
716 const char* comment, int method, int level, int zip64);
717
718 /*
719 Open a file in the ZIP for writing.
720 filename : the filename in zip (if NULL, '-' without quote will be used
721 *zipfi contain supplemental information
722 if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
723 contains the extrafield data for the local header
724 if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
725 contains the extrafield data for the global header
726 if comment != NULL, comment contain the comment string
727 method contain the compression method (0 for store, Z_DEFLATED for deflate)
728 level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
729 zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
730 this MUST be '1' if the uncompressed size is >= 0xffffffff.
731
732*/
733
734 extern int ZEXPORT zipOpenNewFileInZip2 (zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local,
735 uInt size_extrafield_local, const void* extrafield_global, uInt size_extrafield_global,
736 const char* comment, int method, int level, int raw);
737
738 extern int ZEXPORT zipOpenNewFileInZip2_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local,
739 uInt size_extrafield_local, const void* extrafield_global, uInt size_extrafield_global,
740 const char* comment, int method, int level, int raw, int zip64);
741 /*
742 Same than zipOpenNewFileInZip, except if raw=1, we write raw file
743 */
744
745 extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local,
746 uInt size_extrafield_local, const void* extrafield_global, uInt size_extrafield_global,
747 const char* comment, int method, int level, int raw, int windowBits, int memLevel,
748 int strategy, const char* password, uLong crcForCrypting);
749
750 extern int ZEXPORT zipOpenNewFileInZip3_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local,
751 uInt size_extrafield_local, const void* extrafield_global, uInt size_extrafield_global,
752 const char* comment, int method, int level, int raw, int windowBits, int memLevel,
753 int strategy, const char* password, uLong crcForCrypting, int zip64);
754
755 /*
756 Same than zipOpenNewFileInZip2, except
757 windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
758 password : crypting password (NULL for no crypting)
759 crcForCrypting : crc of file to compress (needed for crypting)
760 */
761
762 extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local,
763 uInt size_extrafield_local, const void* extrafield_global, uInt size_extrafield_global,
764 const char* comment, int method, int level, int raw, int windowBits, int memLevel,
765 int strategy, const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase);
766
767 extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, const void* extrafield_local,
768 uInt size_extrafield_local, const void* extrafield_global, uInt size_extrafield_global,
769 const char* comment, int method, int level, int raw, int windowBits, int memLevel, int strategy,
770 const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase, int zip64);
771 /*
772 Same than zipOpenNewFileInZip4, except
773 versionMadeBy : value for Version made by field
774 flag : value for flag field (compression level info will be added)
775 */
776
777 extern int ZEXPORT zipWriteInFileInZip (zipFile file, const void* buf, unsigned len);
778 /*
779 Write data in the zipfile
780*/
781
782 extern int ZEXPORT zipCloseFileInZip (zipFile file);
783 /*
784 Close the current file in the zipfile
785*/
786
787 extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32);
788
789 extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32);
790
791 /*
792 Close the current file in the zipfile, for file opened with
793 parameter raw=1 in zipOpenNewFileInZip2
794 uncompressed_size and crc32 are value for the uncompressed size
795*/
796
797 extern int ZEXPORT zipClose (zipFile file, const char* global_comment);
798 /*
799 Close the zipfile
800*/
801
802 extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader);
803 /*
804 zipRemoveExtraInfoBlock - Added by Mathias Svensson
805
806 Remove extra information block from a extra information data for the local file header or central directory header
807
808 It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
809
810 0x0001 is the signature header for the ZIP64 extra information blocks
811
812 usage.
813 Remove ZIP64 Extra information from a central director extra field data
814 zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
815
816 Remove ZIP64 Extra information from a Local File Header extra field data
817 zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
818*/
819 /// END OF ZIP.h
820
821}
822#endif
STL namespace.