packio-simple
diff src/minizip/unzip.h @ 0:d81c3ae262a0
initial commit
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Sun, 09 Sep 2012 06:05:11 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/minizip/unzip.h Sun Sep 09 06:05:11 2012 +0300 1.3 @@ -0,0 +1,437 @@ 1.4 +/* unzip.h -- IO for uncompress .zip files using zlib 1.5 + Version 1.1, February 14h, 2010 1.6 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) 1.7 + 1.8 + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) 1.9 + 1.10 + Modifications of Unzip for Zip64 1.11 + Copyright (C) 2007-2008 Even Rouault 1.12 + 1.13 + Modifications for Zip64 support on both zip and unzip 1.14 + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 1.15 + 1.16 + For more info read MiniZip_info.txt 1.17 + 1.18 + --------------------------------------------------------------------------------- 1.19 + 1.20 + Condition of use and distribution are the same than zlib : 1.21 + 1.22 + This software is provided 'as-is', without any express or implied 1.23 + warranty. In no event will the authors be held liable for any damages 1.24 + arising from the use of this software. 1.25 + 1.26 + Permission is granted to anyone to use this software for any purpose, 1.27 + including commercial applications, and to alter it and redistribute it 1.28 + freely, subject to the following restrictions: 1.29 + 1.30 + 1. The origin of this software must not be misrepresented; you must not 1.31 + claim that you wrote the original software. If you use this software 1.32 + in a product, an acknowledgment in the product documentation would be 1.33 + appreciated but is not required. 1.34 + 2. Altered source versions must be plainly marked as such, and must not be 1.35 + misrepresented as being the original software. 1.36 + 3. This notice may not be removed or altered from any source distribution. 1.37 + 1.38 + --------------------------------------------------------------------------------- 1.39 + 1.40 + Changes 1.41 + 1.42 + See header of unzip64.c 1.43 + 1.44 +*/ 1.45 + 1.46 +#ifndef _unz64_H 1.47 +#define _unz64_H 1.48 + 1.49 +#ifdef __cplusplus 1.50 +extern "C" { 1.51 +#endif 1.52 + 1.53 +#ifndef _ZLIB_H 1.54 +#include "zlib.h" 1.55 +#endif 1.56 + 1.57 +#ifndef _ZLIBIOAPI_H 1.58 +#include "ioapi.h" 1.59 +#endif 1.60 + 1.61 +#ifdef HAVE_BZIP2 1.62 +#include "bzlib.h" 1.63 +#endif 1.64 + 1.65 +#define Z_BZIP2ED 12 1.66 + 1.67 +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 1.68 +/* like the STRICT of WIN32, we define a pointer that cannot be converted 1.69 + from (void*) without cast */ 1.70 +typedef struct TagunzFile__ { int unused; } unzFile__; 1.71 +typedef unzFile__ *unzFile; 1.72 +#else 1.73 +typedef voidp unzFile; 1.74 +#endif 1.75 + 1.76 + 1.77 +#define UNZ_OK (0) 1.78 +#define UNZ_END_OF_LIST_OF_FILE (-100) 1.79 +#define UNZ_ERRNO (Z_ERRNO) 1.80 +#define UNZ_EOF (0) 1.81 +#define UNZ_PARAMERROR (-102) 1.82 +#define UNZ_BADZIPFILE (-103) 1.83 +#define UNZ_INTERNALERROR (-104) 1.84 +#define UNZ_CRCERROR (-105) 1.85 + 1.86 +/* tm_unz contain date/time info */ 1.87 +typedef struct tm_unz_s 1.88 +{ 1.89 + uInt tm_sec; /* seconds after the minute - [0,59] */ 1.90 + uInt tm_min; /* minutes after the hour - [0,59] */ 1.91 + uInt tm_hour; /* hours since midnight - [0,23] */ 1.92 + uInt tm_mday; /* day of the month - [1,31] */ 1.93 + uInt tm_mon; /* months since January - [0,11] */ 1.94 + uInt tm_year; /* years - [1980..2044] */ 1.95 +} tm_unz; 1.96 + 1.97 +/* unz_global_info structure contain global data about the ZIPfile 1.98 + These data comes from the end of central dir */ 1.99 +typedef struct unz_global_info64_s 1.100 +{ 1.101 + ZPOS64_T number_entry; /* total number of entries in 1.102 + the central dir on this disk */ 1.103 + uLong size_comment; /* size of the global comment of the zipfile */ 1.104 +} unz_global_info64; 1.105 + 1.106 +typedef struct unz_global_info_s 1.107 +{ 1.108 + uLong number_entry; /* total number of entries in 1.109 + the central dir on this disk */ 1.110 + uLong size_comment; /* size of the global comment of the zipfile */ 1.111 +} unz_global_info; 1.112 + 1.113 +/* unz_file_info contain information about a file in the zipfile */ 1.114 +typedef struct unz_file_info64_s 1.115 +{ 1.116 + uLong version; /* version made by 2 bytes */ 1.117 + uLong version_needed; /* version needed to extract 2 bytes */ 1.118 + uLong flag; /* general purpose bit flag 2 bytes */ 1.119 + uLong compression_method; /* compression method 2 bytes */ 1.120 + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 1.121 + uLong crc; /* crc-32 4 bytes */ 1.122 + ZPOS64_T compressed_size; /* compressed size 8 bytes */ 1.123 + ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ 1.124 + uLong size_filename; /* filename length 2 bytes */ 1.125 + uLong size_file_extra; /* extra field length 2 bytes */ 1.126 + uLong size_file_comment; /* file comment length 2 bytes */ 1.127 + 1.128 + uLong disk_num_start; /* disk number start 2 bytes */ 1.129 + uLong internal_fa; /* internal file attributes 2 bytes */ 1.130 + uLong external_fa; /* external file attributes 4 bytes */ 1.131 + 1.132 + tm_unz tmu_date; 1.133 +} unz_file_info64; 1.134 + 1.135 +typedef struct unz_file_info_s 1.136 +{ 1.137 + uLong version; /* version made by 2 bytes */ 1.138 + uLong version_needed; /* version needed to extract 2 bytes */ 1.139 + uLong flag; /* general purpose bit flag 2 bytes */ 1.140 + uLong compression_method; /* compression method 2 bytes */ 1.141 + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 1.142 + uLong crc; /* crc-32 4 bytes */ 1.143 + uLong compressed_size; /* compressed size 4 bytes */ 1.144 + uLong uncompressed_size; /* uncompressed size 4 bytes */ 1.145 + uLong size_filename; /* filename length 2 bytes */ 1.146 + uLong size_file_extra; /* extra field length 2 bytes */ 1.147 + uLong size_file_comment; /* file comment length 2 bytes */ 1.148 + 1.149 + uLong disk_num_start; /* disk number start 2 bytes */ 1.150 + uLong internal_fa; /* internal file attributes 2 bytes */ 1.151 + uLong external_fa; /* external file attributes 4 bytes */ 1.152 + 1.153 + tm_unz tmu_date; 1.154 +} unz_file_info; 1.155 + 1.156 +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, 1.157 + const char* fileName2, 1.158 + int iCaseSensitivity)); 1.159 +/* 1.160 + Compare two filename (fileName1,fileName2). 1.161 + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 1.162 + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 1.163 + or strcasecmp) 1.164 + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system 1.165 + (like 1 on Unix, 2 on Windows) 1.166 +*/ 1.167 + 1.168 + 1.169 +extern unzFile ZEXPORT unzOpen OF((const char *path)); 1.170 +extern unzFile ZEXPORT unzOpen64 OF((const void *path)); 1.171 +/* 1.172 + Open a Zip file. path contain the full pathname (by example, 1.173 + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer 1.174 + "zlib/zlib113.zip". 1.175 + If the zipfile cannot be opened (file don't exist or in not valid), the 1.176 + return value is NULL. 1.177 + Else, the return value is a unzFile Handle, usable with other function 1.178 + of this unzip package. 1.179 + the "64" function take a const void* pointer, because the path is just the 1.180 + value passed to the open64_file_func callback. 1.181 + Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path 1.182 + is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* 1.183 + does not describe the reality 1.184 +*/ 1.185 + 1.186 + 1.187 +extern unzFile ZEXPORT unzOpen2 OF((const char *path, 1.188 + zlib_filefunc_def* pzlib_filefunc_def)); 1.189 +/* 1.190 + Open a Zip file, like unzOpen, but provide a set of file low level API 1.191 + for read/write the zip file (see ioapi.h) 1.192 +*/ 1.193 + 1.194 +extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, 1.195 + zlib_filefunc64_def* pzlib_filefunc_def)); 1.196 +/* 1.197 + Open a Zip file, like unz64Open, but provide a set of file low level API 1.198 + for read/write the zip file (see ioapi.h) 1.199 +*/ 1.200 + 1.201 +extern int ZEXPORT unzClose OF((unzFile file)); 1.202 +/* 1.203 + Close a ZipFile opened with unzipOpen. 1.204 + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), 1.205 + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 1.206 + return UNZ_OK if there is no problem. */ 1.207 + 1.208 +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, 1.209 + unz_global_info *pglobal_info)); 1.210 + 1.211 +extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, 1.212 + unz_global_info64 *pglobal_info)); 1.213 +/* 1.214 + Write info about the ZipFile in the *pglobal_info structure. 1.215 + No preparation of the structure is needed 1.216 + return UNZ_OK if there is no problem. */ 1.217 + 1.218 + 1.219 +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, 1.220 + char *szComment, 1.221 + uLong uSizeBuf)); 1.222 +/* 1.223 + Get the global comment string of the ZipFile, in the szComment buffer. 1.224 + uSizeBuf is the size of the szComment buffer. 1.225 + return the number of byte copied or an error code <0 1.226 +*/ 1.227 + 1.228 + 1.229 +/***************************************************************************/ 1.230 +/* Unzip package allow you browse the directory of the zipfile */ 1.231 + 1.232 +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); 1.233 +/* 1.234 + Set the current file of the zipfile to the first file. 1.235 + return UNZ_OK if there is no problem 1.236 +*/ 1.237 + 1.238 +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); 1.239 +/* 1.240 + Set the current file of the zipfile to the next file. 1.241 + return UNZ_OK if there is no problem 1.242 + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 1.243 +*/ 1.244 + 1.245 +extern int ZEXPORT unzLocateFile OF((unzFile file, 1.246 + const char *szFileName, 1.247 + int iCaseSensitivity)); 1.248 +/* 1.249 + Try locate the file szFileName in the zipfile. 1.250 + For the iCaseSensitivity signification, see unzStringFileNameCompare 1.251 + 1.252 + return value : 1.253 + UNZ_OK if the file is found. It becomes the current file. 1.254 + UNZ_END_OF_LIST_OF_FILE if the file is not found 1.255 +*/ 1.256 + 1.257 + 1.258 +/* ****************************************** */ 1.259 +/* Ryan supplied functions */ 1.260 +/* unz_file_info contain information about a file in the zipfile */ 1.261 +typedef struct unz_file_pos_s 1.262 +{ 1.263 + uLong pos_in_zip_directory; /* offset in zip file directory */ 1.264 + uLong num_of_file; /* # of file */ 1.265 +} unz_file_pos; 1.266 + 1.267 +extern int ZEXPORT unzGetFilePos( 1.268 + unzFile file, 1.269 + unz_file_pos* file_pos); 1.270 + 1.271 +extern int ZEXPORT unzGoToFilePos( 1.272 + unzFile file, 1.273 + unz_file_pos* file_pos); 1.274 + 1.275 +typedef struct unz64_file_pos_s 1.276 +{ 1.277 + ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ 1.278 + ZPOS64_T num_of_file; /* # of file */ 1.279 +} unz64_file_pos; 1.280 + 1.281 +extern int ZEXPORT unzGetFilePos64( 1.282 + unzFile file, 1.283 + unz64_file_pos* file_pos); 1.284 + 1.285 +extern int ZEXPORT unzGoToFilePos64( 1.286 + unzFile file, 1.287 + const unz64_file_pos* file_pos); 1.288 + 1.289 +/* ****************************************** */ 1.290 + 1.291 +extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, 1.292 + unz_file_info64 *pfile_info, 1.293 + char *szFileName, 1.294 + uLong fileNameBufferSize, 1.295 + void *extraField, 1.296 + uLong extraFieldBufferSize, 1.297 + char *szComment, 1.298 + uLong commentBufferSize)); 1.299 + 1.300 +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, 1.301 + unz_file_info *pfile_info, 1.302 + char *szFileName, 1.303 + uLong fileNameBufferSize, 1.304 + void *extraField, 1.305 + uLong extraFieldBufferSize, 1.306 + char *szComment, 1.307 + uLong commentBufferSize)); 1.308 +/* 1.309 + Get Info about the current file 1.310 + if pfile_info!=NULL, the *pfile_info structure will contain somes info about 1.311 + the current file 1.312 + if szFileName!=NULL, the filemane string will be copied in szFileName 1.313 + (fileNameBufferSize is the size of the buffer) 1.314 + if extraField!=NULL, the extra field information will be copied in extraField 1.315 + (extraFieldBufferSize is the size of the buffer). 1.316 + This is the Central-header version of the extra field 1.317 + if szComment!=NULL, the comment string of the file will be copied in szComment 1.318 + (commentBufferSize is the size of the buffer) 1.319 +*/ 1.320 + 1.321 + 1.322 +/** Addition for GDAL : START */ 1.323 + 1.324 +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); 1.325 + 1.326 +/** Addition for GDAL : END */ 1.327 + 1.328 + 1.329 +/***************************************************************************/ 1.330 +/* for reading the content of the current zipfile, you can open it, read data 1.331 + from it, and close it (you can close it before reading all the file) 1.332 + */ 1.333 + 1.334 +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); 1.335 +/* 1.336 + Open for reading data the current file in the zipfile. 1.337 + If there is no error, the return value is UNZ_OK. 1.338 +*/ 1.339 + 1.340 +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, 1.341 + const char* password)); 1.342 +/* 1.343 + Open for reading data the current file in the zipfile. 1.344 + password is a crypting password 1.345 + If there is no error, the return value is UNZ_OK. 1.346 +*/ 1.347 + 1.348 +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, 1.349 + int* method, 1.350 + int* level, 1.351 + int raw)); 1.352 +/* 1.353 + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 1.354 + if raw==1 1.355 + *method will receive method of compression, *level will receive level of 1.356 + compression 1.357 + note : you can set level parameter as NULL (if you did not want known level, 1.358 + but you CANNOT set method parameter as NULL 1.359 +*/ 1.360 + 1.361 +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, 1.362 + int* method, 1.363 + int* level, 1.364 + int raw, 1.365 + const char* password)); 1.366 +/* 1.367 + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 1.368 + if raw==1 1.369 + *method will receive method of compression, *level will receive level of 1.370 + compression 1.371 + note : you can set level parameter as NULL (if you did not want known level, 1.372 + but you CANNOT set method parameter as NULL 1.373 +*/ 1.374 + 1.375 + 1.376 +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); 1.377 +/* 1.378 + Close the file in zip opened with unzOpenCurrentFile 1.379 + Return UNZ_CRCERROR if all the file was read but the CRC is not good 1.380 +*/ 1.381 + 1.382 +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, 1.383 + voidp buf, 1.384 + unsigned len)); 1.385 +/* 1.386 + Read bytes from the current file (opened by unzOpenCurrentFile) 1.387 + buf contain buffer where data must be copied 1.388 + len the size of buf. 1.389 + 1.390 + return the number of byte copied if somes bytes are copied 1.391 + return 0 if the end of file was reached 1.392 + return <0 with error code if there is an error 1.393 + (UNZ_ERRNO for IO error, or zLib error for uncompress error) 1.394 +*/ 1.395 + 1.396 +extern z_off_t ZEXPORT unztell OF((unzFile file)); 1.397 + 1.398 +extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); 1.399 +/* 1.400 + Give the current position in uncompressed data 1.401 +*/ 1.402 + 1.403 +extern int ZEXPORT unzeof OF((unzFile file)); 1.404 +/* 1.405 + return 1 if the end of file was reached, 0 elsewhere 1.406 +*/ 1.407 + 1.408 +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, 1.409 + voidp buf, 1.410 + unsigned len)); 1.411 +/* 1.412 + Read extra field from the current file (opened by unzOpenCurrentFile) 1.413 + This is the local-header version of the extra field (sometimes, there is 1.414 + more info in the local-header version than in the central-header) 1.415 + 1.416 + if buf==NULL, it return the size of the local extra field 1.417 + 1.418 + if buf!=NULL, len is the size of the buffer, the extra header is copied in 1.419 + buf. 1.420 + the return value is the number of bytes copied in buf, or (if <0) 1.421 + the error code 1.422 +*/ 1.423 + 1.424 +/***************************************************************************/ 1.425 + 1.426 +/* Get the current file offset */ 1.427 +extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); 1.428 +extern uLong ZEXPORT unzGetOffset (unzFile file); 1.429 + 1.430 +/* Set the current file offset */ 1.431 +extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); 1.432 +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); 1.433 + 1.434 + 1.435 + 1.436 +#ifdef __cplusplus 1.437 +} 1.438 +#endif 1.439 + 1.440 +#endif /* _unz64_H */