File indexing completed on 2025-01-26 04:24:55
0001 /* unzip.h -- IO for uncompress .zip files using zlib 0002 Version 1.1, February 14h, 2010 0003 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 0004 0005 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 0006 0007 Modifications of Unzip for Zip64 0008 Copyright (C) 2007-2008 Even Rouault 0009 0010 Modifications for Zip64 support on both zip and unzip 0011 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 0012 0013 For more info read MiniZip_info.txt 0014 0015 --------------------------------------------------------------------------------- 0016 0017 Condition of use and distribution are the same than zlib : 0018 0019 This software is provided 'as-is', without any express or implied 0020 warranty. In no event will the authors be held liable for any damages 0021 arising from the use of this software. 0022 0023 Permission is granted to anyone to use this software for any purpose, 0024 including commercial applications, and to alter it and redistribute it 0025 freely, subject to the following restrictions: 0026 0027 1. The origin of this software must not be misrepresented; you must not 0028 claim that you wrote the original software. If you use this software 0029 in a product, an acknowledgment in the product documentation would be 0030 appreciated but is not required. 0031 2. Altered source versions must be plainly marked as such, and must not be 0032 misrepresented as being the original software. 0033 3. This notice may not be removed or altered from any source distribution. 0034 0035 --------------------------------------------------------------------------------- 0036 0037 Changes 0038 0039 See header of unzip64.c 0040 0041 --------------------------------------------------------------------------- 0042 0043 As per the requirement above, this file is plainly marked as modified 0044 by Sergey A. Tachenov. Most modifications include the I/O API redesign 0045 to support QIODevice interface. Some improvements and small fixes were also made. 0046 */ 0047 0048 #ifndef _unz64_H 0049 #define _unz64_H 0050 0051 #ifdef __cplusplus 0052 extern "C" { 0053 #endif 0054 0055 #ifndef _ZLIB_H 0056 #include "zlib.h" 0057 #endif 0058 0059 #ifndef _ZLIBIOAPI_H 0060 #include "ioapi.h" 0061 #endif 0062 0063 #ifdef HAVE_BZIP2 0064 #include "bzlib.h" 0065 #endif 0066 0067 #define Z_BZIP2ED 12 0068 0069 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 0070 /* like the STRICT of WIN32, we define a pointer that cannot be converted 0071 from (void*) without cast */ 0072 typedef struct TagunzFile__ { int unused; } unzFile__; 0073 typedef unzFile__ *unzFile; 0074 #else 0075 typedef voidp unzFile; 0076 #endif 0077 0078 0079 #define UNZ_OK (0) 0080 #define UNZ_END_OF_LIST_OF_FILE (-100) 0081 #define UNZ_ERRNO (Z_ERRNO) 0082 #define UNZ_EOF (0) 0083 #define UNZ_PARAMERROR (-102) 0084 #define UNZ_BADZIPFILE (-103) 0085 #define UNZ_INTERNALERROR (-104) 0086 #define UNZ_CRCERROR (-105) 0087 0088 #define UNZ_AUTO_CLOSE 0x01u 0089 #define UNZ_DEFAULT_FLAGS UNZ_AUTO_CLOSE 0090 0091 /* tm_unz contain date/time info */ 0092 typedef struct tm_unz_s 0093 { 0094 uInt tm_sec; /* seconds after the minute - [0,59] */ 0095 uInt tm_min; /* minutes after the hour - [0,59] */ 0096 uInt tm_hour; /* hours since midnight - [0,23] */ 0097 uInt tm_mday; /* day of the month - [1,31] */ 0098 uInt tm_mon; /* months since January - [0,11] */ 0099 uInt tm_year; /* years - [1980..2044] */ 0100 } tm_unz; 0101 0102 /* unz_global_info structure contain global data about the ZIPfile 0103 These data comes from the end of central dir */ 0104 typedef struct unz_global_info64_s 0105 { 0106 ZPOS64_T number_entry; /* total number of entries in 0107 the central dir on this disk */ 0108 uLong size_comment; /* size of the global comment of the zipfile */ 0109 } unz_global_info64; 0110 0111 typedef struct unz_global_info_s 0112 { 0113 uLong number_entry; /* total number of entries in 0114 the central dir on this disk */ 0115 uLong size_comment; /* size of the global comment of the zipfile */ 0116 } unz_global_info; 0117 0118 /* unz_file_info contain information about a file in the zipfile */ 0119 typedef struct unz_file_info64_s 0120 { 0121 uLong version; /* version made by 2 bytes */ 0122 uLong version_needed; /* version needed to extract 2 bytes */ 0123 uLong flag; /* general purpose bit flag 2 bytes */ 0124 uLong compression_method; /* compression method 2 bytes */ 0125 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 0126 uLong crc; /* crc-32 4 bytes */ 0127 ZPOS64_T compressed_size; /* compressed size 8 bytes */ 0128 ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ 0129 uLong size_filename; /* filename length 2 bytes */ 0130 uLong size_file_extra; /* extra field length 2 bytes */ 0131 uLong size_file_comment; /* file comment length 2 bytes */ 0132 0133 uLong disk_num_start; /* disk number start 2 bytes */ 0134 uLong internal_fa; /* internal file attributes 2 bytes */ 0135 uLong external_fa; /* external file attributes 4 bytes */ 0136 0137 tm_unz tmu_date; 0138 } unz_file_info64; 0139 0140 typedef struct unz_file_info_s 0141 { 0142 uLong version; /* version made by 2 bytes */ 0143 uLong version_needed; /* version needed to extract 2 bytes */ 0144 uLong flag; /* general purpose bit flag 2 bytes */ 0145 uLong compression_method; /* compression method 2 bytes */ 0146 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 0147 uLong crc; /* crc-32 4 bytes */ 0148 uLong compressed_size; /* compressed size 4 bytes */ 0149 uLong uncompressed_size; /* uncompressed size 4 bytes */ 0150 uLong size_filename; /* filename length 2 bytes */ 0151 uLong size_file_extra; /* extra field length 2 bytes */ 0152 uLong size_file_comment; /* file comment length 2 bytes */ 0153 0154 uLong disk_num_start; /* disk number start 2 bytes */ 0155 uLong internal_fa; /* internal file attributes 2 bytes */ 0156 uLong external_fa; /* external file attributes 4 bytes */ 0157 0158 tm_unz tmu_date; 0159 } unz_file_info; 0160 0161 extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, 0162 const char* fileName2, 0163 int iCaseSensitivity)); 0164 /* 0165 Compare two filename (fileName1,fileName2). 0166 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 0167 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 0168 or strcasecmp) 0169 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system 0170 (like 1 on Unix, 2 on Windows) 0171 */ 0172 0173 0174 extern unzFile ZEXPORT unzOpen OF((voidpf file)); 0175 extern unzFile ZEXPORT unzOpen64 OF((voidpf file)); 0176 /* 0177 Open a Zip file. path contain the full pathname (by example, 0178 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer 0179 "zlib/zlib113.zip". 0180 If the zipfile cannot be opened (file don't exist or in not valid), the 0181 return value is NULL. 0182 Else, the return value is a unzFile Handle, usable with other function 0183 of this unzip package. 0184 the "64" function take a const void* pointer, because the path is just the 0185 value passed to the open64_file_func callback. 0186 Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path 0187 is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* 0188 does not describe the reality 0189 */ 0190 0191 0192 extern unzFile ZEXPORT unzOpen2 OF((voidpf file, 0193 zlib_filefunc_def* pzlib_filefunc_def)); 0194 /* 0195 Open a Zip file, like unzOpen, but provide a set of file low level API 0196 for read/write the zip file (see ioapi.h) 0197 */ 0198 0199 extern unzFile ZEXPORT unzOpen2_64 OF((voidpf file, 0200 zlib_filefunc64_def* pzlib_filefunc_def)); 0201 /* 0202 Open a Zip file, like unz64Open, but provide a set of file low level API 0203 for read/write the zip file (see ioapi.h) 0204 */ 0205 0206 0207 /* 0208 * Exported by Sergey A. Tachenov to implement some QuaZIP features. This 0209 * function MAY change signature in order to implement even more features. 0210 * You have been warned! 0211 * */ 0212 extern unzFile unzOpenInternal (voidpf file, 0213 zlib_filefunc64_32_def* pzlib_filefunc64_32_def, 0214 int is64bitOpenFunction, unsigned flags); 0215 0216 0217 0218 extern int ZEXPORT unzClose OF((unzFile file)); 0219 /* 0220 Close a ZipFile opened with unzipOpen. 0221 If there is files inside the .Zip opened with unzOpenCurrentFile (see later), 0222 these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 0223 return UNZ_OK if there is no problem. */ 0224 0225 extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, 0226 unz_global_info *pglobal_info)); 0227 0228 extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, 0229 unz_global_info64 *pglobal_info)); 0230 /* 0231 Write info about the ZipFile in the *pglobal_info structure. 0232 No preparation of the structure is needed 0233 return UNZ_OK if there is no problem. */ 0234 0235 0236 extern int ZEXPORT unzGetGlobalComment OF((unzFile file, 0237 char *szComment, 0238 uLong uSizeBuf)); 0239 /* 0240 Get the global comment string of the ZipFile, in the szComment buffer. 0241 uSizeBuf is the size of the szComment buffer. 0242 return the number of byte copied or an error code <0 0243 */ 0244 0245 0246 /***************************************************************************/ 0247 /* Unzip package allow you browse the directory of the zipfile */ 0248 0249 extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); 0250 /* 0251 Set the current file of the zipfile to the first file. 0252 return UNZ_OK if there is no problem 0253 */ 0254 0255 extern int ZEXPORT unzGoToNextFile OF((unzFile file)); 0256 /* 0257 Set the current file of the zipfile to the next file. 0258 return UNZ_OK if there is no problem 0259 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 0260 */ 0261 0262 extern int ZEXPORT unzLocateFile OF((unzFile file, 0263 const char *szFileName, 0264 int iCaseSensitivity)); 0265 /* 0266 Try locate the file szFileName in the zipfile. 0267 For the iCaseSensitivity signification, see unzStringFileNameCompare 0268 0269 return value : 0270 UNZ_OK if the file is found. It becomes the current file. 0271 UNZ_END_OF_LIST_OF_FILE if the file is not found 0272 */ 0273 0274 0275 /* ****************************************** */ 0276 /* Ryan supplied functions */ 0277 /* unz_file_info contain information about a file in the zipfile */ 0278 typedef struct unz_file_pos_s 0279 { 0280 uLong pos_in_zip_directory; /* offset in zip file directory */ 0281 uLong num_of_file; /* # of file */ 0282 } unz_file_pos; 0283 0284 extern int ZEXPORT unzGetFilePos( 0285 unzFile file, 0286 unz_file_pos* file_pos); 0287 0288 extern int ZEXPORT unzGoToFilePos( 0289 unzFile file, 0290 unz_file_pos* file_pos); 0291 0292 typedef struct unz64_file_pos_s 0293 { 0294 ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ 0295 ZPOS64_T num_of_file; /* # of file */ 0296 } unz64_file_pos; 0297 0298 extern int ZEXPORT unzGetFilePos64( 0299 unzFile file, 0300 unz64_file_pos* file_pos); 0301 0302 extern int ZEXPORT unzGoToFilePos64( 0303 unzFile file, 0304 const unz64_file_pos* file_pos); 0305 0306 /* ****************************************** */ 0307 0308 extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, 0309 unz_file_info64 *pfile_info, 0310 char *szFileName, 0311 uLong fileNameBufferSize, 0312 void *extraField, 0313 uLong extraFieldBufferSize, 0314 char *szComment, 0315 uLong commentBufferSize)); 0316 0317 extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, 0318 unz_file_info *pfile_info, 0319 char *szFileName, 0320 uLong fileNameBufferSize, 0321 void *extraField, 0322 uLong extraFieldBufferSize, 0323 char *szComment, 0324 uLong commentBufferSize)); 0325 /* 0326 Get Info about the current file 0327 if pfile_info!=NULL, the *pfile_info structure will contain somes info about 0328 the current file 0329 if szFileName!=NULL, the filemane string will be copied in szFileName 0330 (fileNameBufferSize is the size of the buffer) 0331 if extraField!=NULL, the extra field information will be copied in extraField 0332 (extraFieldBufferSize is the size of the buffer). 0333 This is the Central-header version of the extra field 0334 if szComment!=NULL, the comment string of the file will be copied in szComment 0335 (commentBufferSize is the size of the buffer) 0336 */ 0337 0338 0339 /** Addition for GDAL : START */ 0340 0341 extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); 0342 0343 /** Addition for GDAL : END */ 0344 0345 0346 /***************************************************************************/ 0347 /* for reading the content of the current zipfile, you can open it, read data 0348 from it, and close it (you can close it before reading all the file) 0349 */ 0350 0351 extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); 0352 /* 0353 Open for reading data the current file in the zipfile. 0354 If there is no error, the return value is UNZ_OK. 0355 */ 0356 0357 extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, 0358 const char* password)); 0359 /* 0360 Open for reading data the current file in the zipfile. 0361 password is a crypting password 0362 If there is no error, the return value is UNZ_OK. 0363 */ 0364 0365 extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, 0366 int* method, 0367 int* level, 0368 int raw)); 0369 /* 0370 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 0371 if raw==1 0372 *method will receive method of compression, *level will receive level of 0373 compression 0374 note : you can set level parameter as NULL (if you did not want known level, 0375 but you CANNOT set method parameter as NULL 0376 */ 0377 0378 extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, 0379 int* method, 0380 int* level, 0381 int raw, 0382 const char* password)); 0383 /* 0384 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 0385 if raw==1 0386 *method will receive method of compression, *level will receive level of 0387 compression 0388 note : you can set level parameter as NULL (if you did not want known level, 0389 but you CANNOT set method parameter as NULL 0390 */ 0391 0392 0393 extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); 0394 /* 0395 Close the file in zip opened with unzOpenCurrentFile 0396 Return UNZ_CRCERROR if all the file was read but the CRC is not good 0397 */ 0398 0399 extern int ZEXPORT unzReadCurrentFile OF((unzFile file, 0400 voidp buf, 0401 unsigned len)); 0402 /* 0403 Read bytes from the current file (opened by unzOpenCurrentFile) 0404 buf contain buffer where data must be copied 0405 len the size of buf. 0406 0407 return the number of byte copied if somes bytes are copied 0408 return 0 if the end of file was reached 0409 return <0 with error code if there is an error 0410 (UNZ_ERRNO for IO error, or zLib error for uncompress error) 0411 */ 0412 0413 extern z_off_t ZEXPORT unztell OF((unzFile file)); 0414 0415 extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); 0416 /* 0417 Give the current position in uncompressed data 0418 */ 0419 0420 extern int ZEXPORT unzeof OF((unzFile file)); 0421 /* 0422 return 1 if the end of file was reached, 0 elsewhere 0423 */ 0424 0425 extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, 0426 voidp buf, 0427 unsigned len)); 0428 /* 0429 Read extra field from the current file (opened by unzOpenCurrentFile) 0430 This is the local-header version of the extra field (sometimes, there is 0431 more info in the local-header version than in the central-header) 0432 0433 if buf==NULL, it return the size of the local extra field 0434 0435 if buf!=NULL, len is the size of the buffer, the extra header is copied in 0436 buf. 0437 the return value is the number of bytes copied in buf, or (if <0) 0438 the error code 0439 */ 0440 0441 /***************************************************************************/ 0442 0443 /* Get the current file offset */ 0444 extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); 0445 extern uLong ZEXPORT unzGetOffset (unzFile file); 0446 0447 /* Set the current file offset */ 0448 extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); 0449 extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); 0450 0451 extern int ZEXPORT unzSetFlags(unzFile file, unsigned flags); 0452 extern int ZEXPORT unzClearFlags(unzFile file, unsigned flags); 0453 0454 #ifdef __cplusplus 0455 } 0456 #endif 0457 0458 #endif /* _unz64_H */