packio-simple

annotate 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
rev   line source
nuclear@0 1 /* unzip.h -- IO for uncompress .zip files using zlib
nuclear@0 2 Version 1.1, February 14h, 2010
nuclear@0 3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
nuclear@0 4
nuclear@0 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
nuclear@0 6
nuclear@0 7 Modifications of Unzip for Zip64
nuclear@0 8 Copyright (C) 2007-2008 Even Rouault
nuclear@0 9
nuclear@0 10 Modifications for Zip64 support on both zip and unzip
nuclear@0 11 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
nuclear@0 12
nuclear@0 13 For more info read MiniZip_info.txt
nuclear@0 14
nuclear@0 15 ---------------------------------------------------------------------------------
nuclear@0 16
nuclear@0 17 Condition of use and distribution are the same than zlib :
nuclear@0 18
nuclear@0 19 This software is provided 'as-is', without any express or implied
nuclear@0 20 warranty. In no event will the authors be held liable for any damages
nuclear@0 21 arising from the use of this software.
nuclear@0 22
nuclear@0 23 Permission is granted to anyone to use this software for any purpose,
nuclear@0 24 including commercial applications, and to alter it and redistribute it
nuclear@0 25 freely, subject to the following restrictions:
nuclear@0 26
nuclear@0 27 1. The origin of this software must not be misrepresented; you must not
nuclear@0 28 claim that you wrote the original software. If you use this software
nuclear@0 29 in a product, an acknowledgment in the product documentation would be
nuclear@0 30 appreciated but is not required.
nuclear@0 31 2. Altered source versions must be plainly marked as such, and must not be
nuclear@0 32 misrepresented as being the original software.
nuclear@0 33 3. This notice may not be removed or altered from any source distribution.
nuclear@0 34
nuclear@0 35 ---------------------------------------------------------------------------------
nuclear@0 36
nuclear@0 37 Changes
nuclear@0 38
nuclear@0 39 See header of unzip64.c
nuclear@0 40
nuclear@0 41 */
nuclear@0 42
nuclear@0 43 #ifndef _unz64_H
nuclear@0 44 #define _unz64_H
nuclear@0 45
nuclear@0 46 #ifdef __cplusplus
nuclear@0 47 extern "C" {
nuclear@0 48 #endif
nuclear@0 49
nuclear@0 50 #ifndef _ZLIB_H
nuclear@0 51 #include "zlib.h"
nuclear@0 52 #endif
nuclear@0 53
nuclear@0 54 #ifndef _ZLIBIOAPI_H
nuclear@0 55 #include "ioapi.h"
nuclear@0 56 #endif
nuclear@0 57
nuclear@0 58 #ifdef HAVE_BZIP2
nuclear@0 59 #include "bzlib.h"
nuclear@0 60 #endif
nuclear@0 61
nuclear@0 62 #define Z_BZIP2ED 12
nuclear@0 63
nuclear@0 64 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
nuclear@0 65 /* like the STRICT of WIN32, we define a pointer that cannot be converted
nuclear@0 66 from (void*) without cast */
nuclear@0 67 typedef struct TagunzFile__ { int unused; } unzFile__;
nuclear@0 68 typedef unzFile__ *unzFile;
nuclear@0 69 #else
nuclear@0 70 typedef voidp unzFile;
nuclear@0 71 #endif
nuclear@0 72
nuclear@0 73
nuclear@0 74 #define UNZ_OK (0)
nuclear@0 75 #define UNZ_END_OF_LIST_OF_FILE (-100)
nuclear@0 76 #define UNZ_ERRNO (Z_ERRNO)
nuclear@0 77 #define UNZ_EOF (0)
nuclear@0 78 #define UNZ_PARAMERROR (-102)
nuclear@0 79 #define UNZ_BADZIPFILE (-103)
nuclear@0 80 #define UNZ_INTERNALERROR (-104)
nuclear@0 81 #define UNZ_CRCERROR (-105)
nuclear@0 82
nuclear@0 83 /* tm_unz contain date/time info */
nuclear@0 84 typedef struct tm_unz_s
nuclear@0 85 {
nuclear@0 86 uInt tm_sec; /* seconds after the minute - [0,59] */
nuclear@0 87 uInt tm_min; /* minutes after the hour - [0,59] */
nuclear@0 88 uInt tm_hour; /* hours since midnight - [0,23] */
nuclear@0 89 uInt tm_mday; /* day of the month - [1,31] */
nuclear@0 90 uInt tm_mon; /* months since January - [0,11] */
nuclear@0 91 uInt tm_year; /* years - [1980..2044] */
nuclear@0 92 } tm_unz;
nuclear@0 93
nuclear@0 94 /* unz_global_info structure contain global data about the ZIPfile
nuclear@0 95 These data comes from the end of central dir */
nuclear@0 96 typedef struct unz_global_info64_s
nuclear@0 97 {
nuclear@0 98 ZPOS64_T number_entry; /* total number of entries in
nuclear@0 99 the central dir on this disk */
nuclear@0 100 uLong size_comment; /* size of the global comment of the zipfile */
nuclear@0 101 } unz_global_info64;
nuclear@0 102
nuclear@0 103 typedef struct unz_global_info_s
nuclear@0 104 {
nuclear@0 105 uLong number_entry; /* total number of entries in
nuclear@0 106 the central dir on this disk */
nuclear@0 107 uLong size_comment; /* size of the global comment of the zipfile */
nuclear@0 108 } unz_global_info;
nuclear@0 109
nuclear@0 110 /* unz_file_info contain information about a file in the zipfile */
nuclear@0 111 typedef struct unz_file_info64_s
nuclear@0 112 {
nuclear@0 113 uLong version; /* version made by 2 bytes */
nuclear@0 114 uLong version_needed; /* version needed to extract 2 bytes */
nuclear@0 115 uLong flag; /* general purpose bit flag 2 bytes */
nuclear@0 116 uLong compression_method; /* compression method 2 bytes */
nuclear@0 117 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
nuclear@0 118 uLong crc; /* crc-32 4 bytes */
nuclear@0 119 ZPOS64_T compressed_size; /* compressed size 8 bytes */
nuclear@0 120 ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
nuclear@0 121 uLong size_filename; /* filename length 2 bytes */
nuclear@0 122 uLong size_file_extra; /* extra field length 2 bytes */
nuclear@0 123 uLong size_file_comment; /* file comment length 2 bytes */
nuclear@0 124
nuclear@0 125 uLong disk_num_start; /* disk number start 2 bytes */
nuclear@0 126 uLong internal_fa; /* internal file attributes 2 bytes */
nuclear@0 127 uLong external_fa; /* external file attributes 4 bytes */
nuclear@0 128
nuclear@0 129 tm_unz tmu_date;
nuclear@0 130 } unz_file_info64;
nuclear@0 131
nuclear@0 132 typedef struct unz_file_info_s
nuclear@0 133 {
nuclear@0 134 uLong version; /* version made by 2 bytes */
nuclear@0 135 uLong version_needed; /* version needed to extract 2 bytes */
nuclear@0 136 uLong flag; /* general purpose bit flag 2 bytes */
nuclear@0 137 uLong compression_method; /* compression method 2 bytes */
nuclear@0 138 uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
nuclear@0 139 uLong crc; /* crc-32 4 bytes */
nuclear@0 140 uLong compressed_size; /* compressed size 4 bytes */
nuclear@0 141 uLong uncompressed_size; /* uncompressed size 4 bytes */
nuclear@0 142 uLong size_filename; /* filename length 2 bytes */
nuclear@0 143 uLong size_file_extra; /* extra field length 2 bytes */
nuclear@0 144 uLong size_file_comment; /* file comment length 2 bytes */
nuclear@0 145
nuclear@0 146 uLong disk_num_start; /* disk number start 2 bytes */
nuclear@0 147 uLong internal_fa; /* internal file attributes 2 bytes */
nuclear@0 148 uLong external_fa; /* external file attributes 4 bytes */
nuclear@0 149
nuclear@0 150 tm_unz tmu_date;
nuclear@0 151 } unz_file_info;
nuclear@0 152
nuclear@0 153 extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
nuclear@0 154 const char* fileName2,
nuclear@0 155 int iCaseSensitivity));
nuclear@0 156 /*
nuclear@0 157 Compare two filename (fileName1,fileName2).
nuclear@0 158 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
nuclear@0 159 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
nuclear@0 160 or strcasecmp)
nuclear@0 161 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
nuclear@0 162 (like 1 on Unix, 2 on Windows)
nuclear@0 163 */
nuclear@0 164
nuclear@0 165
nuclear@0 166 extern unzFile ZEXPORT unzOpen OF((const char *path));
nuclear@0 167 extern unzFile ZEXPORT unzOpen64 OF((const void *path));
nuclear@0 168 /*
nuclear@0 169 Open a Zip file. path contain the full pathname (by example,
nuclear@0 170 on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
nuclear@0 171 "zlib/zlib113.zip".
nuclear@0 172 If the zipfile cannot be opened (file don't exist or in not valid), the
nuclear@0 173 return value is NULL.
nuclear@0 174 Else, the return value is a unzFile Handle, usable with other function
nuclear@0 175 of this unzip package.
nuclear@0 176 the "64" function take a const void* pointer, because the path is just the
nuclear@0 177 value passed to the open64_file_func callback.
nuclear@0 178 Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
nuclear@0 179 is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
nuclear@0 180 does not describe the reality
nuclear@0 181 */
nuclear@0 182
nuclear@0 183
nuclear@0 184 extern unzFile ZEXPORT unzOpen2 OF((const char *path,
nuclear@0 185 zlib_filefunc_def* pzlib_filefunc_def));
nuclear@0 186 /*
nuclear@0 187 Open a Zip file, like unzOpen, but provide a set of file low level API
nuclear@0 188 for read/write the zip file (see ioapi.h)
nuclear@0 189 */
nuclear@0 190
nuclear@0 191 extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
nuclear@0 192 zlib_filefunc64_def* pzlib_filefunc_def));
nuclear@0 193 /*
nuclear@0 194 Open a Zip file, like unz64Open, but provide a set of file low level API
nuclear@0 195 for read/write the zip file (see ioapi.h)
nuclear@0 196 */
nuclear@0 197
nuclear@0 198 extern int ZEXPORT unzClose OF((unzFile file));
nuclear@0 199 /*
nuclear@0 200 Close a ZipFile opened with unzipOpen.
nuclear@0 201 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
nuclear@0 202 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
nuclear@0 203 return UNZ_OK if there is no problem. */
nuclear@0 204
nuclear@0 205 extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
nuclear@0 206 unz_global_info *pglobal_info));
nuclear@0 207
nuclear@0 208 extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
nuclear@0 209 unz_global_info64 *pglobal_info));
nuclear@0 210 /*
nuclear@0 211 Write info about the ZipFile in the *pglobal_info structure.
nuclear@0 212 No preparation of the structure is needed
nuclear@0 213 return UNZ_OK if there is no problem. */
nuclear@0 214
nuclear@0 215
nuclear@0 216 extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
nuclear@0 217 char *szComment,
nuclear@0 218 uLong uSizeBuf));
nuclear@0 219 /*
nuclear@0 220 Get the global comment string of the ZipFile, in the szComment buffer.
nuclear@0 221 uSizeBuf is the size of the szComment buffer.
nuclear@0 222 return the number of byte copied or an error code <0
nuclear@0 223 */
nuclear@0 224
nuclear@0 225
nuclear@0 226 /***************************************************************************/
nuclear@0 227 /* Unzip package allow you browse the directory of the zipfile */
nuclear@0 228
nuclear@0 229 extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
nuclear@0 230 /*
nuclear@0 231 Set the current file of the zipfile to the first file.
nuclear@0 232 return UNZ_OK if there is no problem
nuclear@0 233 */
nuclear@0 234
nuclear@0 235 extern int ZEXPORT unzGoToNextFile OF((unzFile file));
nuclear@0 236 /*
nuclear@0 237 Set the current file of the zipfile to the next file.
nuclear@0 238 return UNZ_OK if there is no problem
nuclear@0 239 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
nuclear@0 240 */
nuclear@0 241
nuclear@0 242 extern int ZEXPORT unzLocateFile OF((unzFile file,
nuclear@0 243 const char *szFileName,
nuclear@0 244 int iCaseSensitivity));
nuclear@0 245 /*
nuclear@0 246 Try locate the file szFileName in the zipfile.
nuclear@0 247 For the iCaseSensitivity signification, see unzStringFileNameCompare
nuclear@0 248
nuclear@0 249 return value :
nuclear@0 250 UNZ_OK if the file is found. It becomes the current file.
nuclear@0 251 UNZ_END_OF_LIST_OF_FILE if the file is not found
nuclear@0 252 */
nuclear@0 253
nuclear@0 254
nuclear@0 255 /* ****************************************** */
nuclear@0 256 /* Ryan supplied functions */
nuclear@0 257 /* unz_file_info contain information about a file in the zipfile */
nuclear@0 258 typedef struct unz_file_pos_s
nuclear@0 259 {
nuclear@0 260 uLong pos_in_zip_directory; /* offset in zip file directory */
nuclear@0 261 uLong num_of_file; /* # of file */
nuclear@0 262 } unz_file_pos;
nuclear@0 263
nuclear@0 264 extern int ZEXPORT unzGetFilePos(
nuclear@0 265 unzFile file,
nuclear@0 266 unz_file_pos* file_pos);
nuclear@0 267
nuclear@0 268 extern int ZEXPORT unzGoToFilePos(
nuclear@0 269 unzFile file,
nuclear@0 270 unz_file_pos* file_pos);
nuclear@0 271
nuclear@0 272 typedef struct unz64_file_pos_s
nuclear@0 273 {
nuclear@0 274 ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */
nuclear@0 275 ZPOS64_T num_of_file; /* # of file */
nuclear@0 276 } unz64_file_pos;
nuclear@0 277
nuclear@0 278 extern int ZEXPORT unzGetFilePos64(
nuclear@0 279 unzFile file,
nuclear@0 280 unz64_file_pos* file_pos);
nuclear@0 281
nuclear@0 282 extern int ZEXPORT unzGoToFilePos64(
nuclear@0 283 unzFile file,
nuclear@0 284 const unz64_file_pos* file_pos);
nuclear@0 285
nuclear@0 286 /* ****************************************** */
nuclear@0 287
nuclear@0 288 extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
nuclear@0 289 unz_file_info64 *pfile_info,
nuclear@0 290 char *szFileName,
nuclear@0 291 uLong fileNameBufferSize,
nuclear@0 292 void *extraField,
nuclear@0 293 uLong extraFieldBufferSize,
nuclear@0 294 char *szComment,
nuclear@0 295 uLong commentBufferSize));
nuclear@0 296
nuclear@0 297 extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
nuclear@0 298 unz_file_info *pfile_info,
nuclear@0 299 char *szFileName,
nuclear@0 300 uLong fileNameBufferSize,
nuclear@0 301 void *extraField,
nuclear@0 302 uLong extraFieldBufferSize,
nuclear@0 303 char *szComment,
nuclear@0 304 uLong commentBufferSize));
nuclear@0 305 /*
nuclear@0 306 Get Info about the current file
nuclear@0 307 if pfile_info!=NULL, the *pfile_info structure will contain somes info about
nuclear@0 308 the current file
nuclear@0 309 if szFileName!=NULL, the filemane string will be copied in szFileName
nuclear@0 310 (fileNameBufferSize is the size of the buffer)
nuclear@0 311 if extraField!=NULL, the extra field information will be copied in extraField
nuclear@0 312 (extraFieldBufferSize is the size of the buffer).
nuclear@0 313 This is the Central-header version of the extra field
nuclear@0 314 if szComment!=NULL, the comment string of the file will be copied in szComment
nuclear@0 315 (commentBufferSize is the size of the buffer)
nuclear@0 316 */
nuclear@0 317
nuclear@0 318
nuclear@0 319 /** Addition for GDAL : START */
nuclear@0 320
nuclear@0 321 extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
nuclear@0 322
nuclear@0 323 /** Addition for GDAL : END */
nuclear@0 324
nuclear@0 325
nuclear@0 326 /***************************************************************************/
nuclear@0 327 /* for reading the content of the current zipfile, you can open it, read data
nuclear@0 328 from it, and close it (you can close it before reading all the file)
nuclear@0 329 */
nuclear@0 330
nuclear@0 331 extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
nuclear@0 332 /*
nuclear@0 333 Open for reading data the current file in the zipfile.
nuclear@0 334 If there is no error, the return value is UNZ_OK.
nuclear@0 335 */
nuclear@0 336
nuclear@0 337 extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
nuclear@0 338 const char* password));
nuclear@0 339 /*
nuclear@0 340 Open for reading data the current file in the zipfile.
nuclear@0 341 password is a crypting password
nuclear@0 342 If there is no error, the return value is UNZ_OK.
nuclear@0 343 */
nuclear@0 344
nuclear@0 345 extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
nuclear@0 346 int* method,
nuclear@0 347 int* level,
nuclear@0 348 int raw));
nuclear@0 349 /*
nuclear@0 350 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
nuclear@0 351 if raw==1
nuclear@0 352 *method will receive method of compression, *level will receive level of
nuclear@0 353 compression
nuclear@0 354 note : you can set level parameter as NULL (if you did not want known level,
nuclear@0 355 but you CANNOT set method parameter as NULL
nuclear@0 356 */
nuclear@0 357
nuclear@0 358 extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
nuclear@0 359 int* method,
nuclear@0 360 int* level,
nuclear@0 361 int raw,
nuclear@0 362 const char* password));
nuclear@0 363 /*
nuclear@0 364 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
nuclear@0 365 if raw==1
nuclear@0 366 *method will receive method of compression, *level will receive level of
nuclear@0 367 compression
nuclear@0 368 note : you can set level parameter as NULL (if you did not want known level,
nuclear@0 369 but you CANNOT set method parameter as NULL
nuclear@0 370 */
nuclear@0 371
nuclear@0 372
nuclear@0 373 extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
nuclear@0 374 /*
nuclear@0 375 Close the file in zip opened with unzOpenCurrentFile
nuclear@0 376 Return UNZ_CRCERROR if all the file was read but the CRC is not good
nuclear@0 377 */
nuclear@0 378
nuclear@0 379 extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
nuclear@0 380 voidp buf,
nuclear@0 381 unsigned len));
nuclear@0 382 /*
nuclear@0 383 Read bytes from the current file (opened by unzOpenCurrentFile)
nuclear@0 384 buf contain buffer where data must be copied
nuclear@0 385 len the size of buf.
nuclear@0 386
nuclear@0 387 return the number of byte copied if somes bytes are copied
nuclear@0 388 return 0 if the end of file was reached
nuclear@0 389 return <0 with error code if there is an error
nuclear@0 390 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
nuclear@0 391 */
nuclear@0 392
nuclear@0 393 extern z_off_t ZEXPORT unztell OF((unzFile file));
nuclear@0 394
nuclear@0 395 extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
nuclear@0 396 /*
nuclear@0 397 Give the current position in uncompressed data
nuclear@0 398 */
nuclear@0 399
nuclear@0 400 extern int ZEXPORT unzeof OF((unzFile file));
nuclear@0 401 /*
nuclear@0 402 return 1 if the end of file was reached, 0 elsewhere
nuclear@0 403 */
nuclear@0 404
nuclear@0 405 extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
nuclear@0 406 voidp buf,
nuclear@0 407 unsigned len));
nuclear@0 408 /*
nuclear@0 409 Read extra field from the current file (opened by unzOpenCurrentFile)
nuclear@0 410 This is the local-header version of the extra field (sometimes, there is
nuclear@0 411 more info in the local-header version than in the central-header)
nuclear@0 412
nuclear@0 413 if buf==NULL, it return the size of the local extra field
nuclear@0 414
nuclear@0 415 if buf!=NULL, len is the size of the buffer, the extra header is copied in
nuclear@0 416 buf.
nuclear@0 417 the return value is the number of bytes copied in buf, or (if <0)
nuclear@0 418 the error code
nuclear@0 419 */
nuclear@0 420
nuclear@0 421 /***************************************************************************/
nuclear@0 422
nuclear@0 423 /* Get the current file offset */
nuclear@0 424 extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
nuclear@0 425 extern uLong ZEXPORT unzGetOffset (unzFile file);
nuclear@0 426
nuclear@0 427 /* Set the current file offset */
nuclear@0 428 extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
nuclear@0 429 extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
nuclear@0 430
nuclear@0 431
nuclear@0 432
nuclear@0 433 #ifdef __cplusplus
nuclear@0 434 }
nuclear@0 435 #endif
nuclear@0 436
nuclear@0 437 #endif /* _unz64_H */