Chris@4: /* unzip.h -- IO for uncompress .zip files using zlib Chris@4: Version 1.1, February 14h, 2010 Chris@4: part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) Chris@4: Chris@4: Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) Chris@4: Chris@4: Modifications of Unzip for Zip64 Chris@4: Copyright (C) 2007-2008 Even Rouault Chris@4: Chris@4: Modifications for Zip64 support on both zip and unzip Chris@4: Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) Chris@4: Chris@4: For more info read MiniZip_info.txt Chris@4: Chris@4: --------------------------------------------------------------------------------- Chris@4: Chris@4: Condition of use and distribution are the same than zlib : Chris@4: Chris@4: This software is provided 'as-is', without any express or implied Chris@4: warranty. In no event will the authors be held liable for any damages Chris@4: arising from the use of this software. Chris@4: Chris@4: Permission is granted to anyone to use this software for any purpose, Chris@4: including commercial applications, and to alter it and redistribute it Chris@4: freely, subject to the following restrictions: Chris@4: Chris@4: 1. The origin of this software must not be misrepresented; you must not Chris@4: claim that you wrote the original software. If you use this software Chris@4: in a product, an acknowledgment in the product documentation would be Chris@4: appreciated but is not required. Chris@4: 2. Altered source versions must be plainly marked as such, and must not be Chris@4: misrepresented as being the original software. Chris@4: 3. This notice may not be removed or altered from any source distribution. Chris@4: Chris@4: --------------------------------------------------------------------------------- Chris@4: Chris@4: Changes Chris@4: Chris@4: See header of unzip64.c Chris@4: Chris@4: */ Chris@4: Chris@4: #ifndef _unz64_H Chris@4: #define _unz64_H Chris@4: Chris@4: #ifdef __cplusplus Chris@4: extern "C" { Chris@4: #endif Chris@4: Chris@4: #ifndef _ZLIB_H Chris@4: #include "zlib.h" Chris@4: #endif Chris@4: Chris@4: #ifndef _ZLIBIOAPI_H Chris@4: #include "ioapi.h" Chris@4: #endif Chris@4: Chris@4: #ifdef HAVE_BZIP2 Chris@4: #include "bzlib.h" Chris@4: #endif Chris@4: Chris@4: #define Z_BZIP2ED 12 Chris@4: Chris@4: #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) Chris@4: /* like the STRICT of WIN32, we define a pointer that cannot be converted Chris@4: from (void*) without cast */ Chris@4: typedef struct TagunzFile__ { int unused; } unzFile__; Chris@4: typedef unzFile__ *unzFile; Chris@4: #else Chris@4: typedef voidp unzFile; Chris@4: #endif Chris@4: Chris@4: Chris@4: #define UNZ_OK (0) Chris@4: #define UNZ_END_OF_LIST_OF_FILE (-100) Chris@4: #define UNZ_ERRNO (Z_ERRNO) Chris@4: #define UNZ_EOF (0) Chris@4: #define UNZ_PARAMERROR (-102) Chris@4: #define UNZ_BADZIPFILE (-103) Chris@4: #define UNZ_INTERNALERROR (-104) Chris@4: #define UNZ_CRCERROR (-105) Chris@4: Chris@4: /* tm_unz contain date/time info */ Chris@4: typedef struct tm_unz_s Chris@4: { Chris@4: uInt tm_sec; /* seconds after the minute - [0,59] */ Chris@4: uInt tm_min; /* minutes after the hour - [0,59] */ Chris@4: uInt tm_hour; /* hours since midnight - [0,23] */ Chris@4: uInt tm_mday; /* day of the month - [1,31] */ Chris@4: uInt tm_mon; /* months since January - [0,11] */ Chris@4: uInt tm_year; /* years - [1980..2044] */ Chris@4: } tm_unz; Chris@4: Chris@4: /* unz_global_info structure contain global data about the ZIPfile Chris@4: These data comes from the end of central dir */ Chris@4: typedef struct unz_global_info64_s Chris@4: { Chris@4: ZPOS64_T number_entry; /* total number of entries in Chris@4: the central dir on this disk */ Chris@4: uLong size_comment; /* size of the global comment of the zipfile */ Chris@4: } unz_global_info64; Chris@4: Chris@4: typedef struct unz_global_info_s Chris@4: { Chris@4: uLong number_entry; /* total number of entries in Chris@4: the central dir on this disk */ Chris@4: uLong size_comment; /* size of the global comment of the zipfile */ Chris@4: } unz_global_info; Chris@4: Chris@4: /* unz_file_info contain information about a file in the zipfile */ Chris@4: typedef struct unz_file_info64_s Chris@4: { Chris@4: uLong version; /* version made by 2 bytes */ Chris@4: uLong version_needed; /* version needed to extract 2 bytes */ Chris@4: uLong flag; /* general purpose bit flag 2 bytes */ Chris@4: uLong compression_method; /* compression method 2 bytes */ Chris@4: uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ Chris@4: uLong crc; /* crc-32 4 bytes */ Chris@4: ZPOS64_T compressed_size; /* compressed size 8 bytes */ Chris@4: ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ Chris@4: uLong size_filename; /* filename length 2 bytes */ Chris@4: uLong size_file_extra; /* extra field length 2 bytes */ Chris@4: uLong size_file_comment; /* file comment length 2 bytes */ Chris@4: Chris@4: uLong disk_num_start; /* disk number start 2 bytes */ Chris@4: uLong internal_fa; /* internal file attributes 2 bytes */ Chris@4: uLong external_fa; /* external file attributes 4 bytes */ Chris@4: Chris@4: tm_unz tmu_date; Chris@4: } unz_file_info64; Chris@4: Chris@4: typedef struct unz_file_info_s Chris@4: { Chris@4: uLong version; /* version made by 2 bytes */ Chris@4: uLong version_needed; /* version needed to extract 2 bytes */ Chris@4: uLong flag; /* general purpose bit flag 2 bytes */ Chris@4: uLong compression_method; /* compression method 2 bytes */ Chris@4: uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ Chris@4: uLong crc; /* crc-32 4 bytes */ Chris@4: uLong compressed_size; /* compressed size 4 bytes */ Chris@4: uLong uncompressed_size; /* uncompressed size 4 bytes */ Chris@4: uLong size_filename; /* filename length 2 bytes */ Chris@4: uLong size_file_extra; /* extra field length 2 bytes */ Chris@4: uLong size_file_comment; /* file comment length 2 bytes */ Chris@4: Chris@4: uLong disk_num_start; /* disk number start 2 bytes */ Chris@4: uLong internal_fa; /* internal file attributes 2 bytes */ Chris@4: uLong external_fa; /* external file attributes 4 bytes */ Chris@4: Chris@4: tm_unz tmu_date; Chris@4: } unz_file_info; Chris@4: Chris@4: extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, Chris@4: const char* fileName2, Chris@4: int iCaseSensitivity)); Chris@4: /* Chris@4: Compare two filename (fileName1,fileName2). Chris@4: If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) Chris@4: If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi Chris@4: or strcasecmp) Chris@4: If iCaseSenisivity = 0, case sensitivity is defaut of your operating system Chris@4: (like 1 on Unix, 2 on Windows) Chris@4: */ Chris@4: Chris@4: Chris@4: extern unzFile ZEXPORT unzOpen OF((const char *path)); Chris@4: extern unzFile ZEXPORT unzOpen64 OF((const void *path)); Chris@4: /* Chris@4: Open a Zip file. path contain the full pathname (by example, Chris@4: on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer Chris@4: "zlib/zlib113.zip". Chris@4: If the zipfile cannot be opened (file don't exist or in not valid), the Chris@4: return value is NULL. Chris@4: Else, the return value is a unzFile Handle, usable with other function Chris@4: of this unzip package. Chris@4: the "64" function take a const void* pointer, because the path is just the Chris@4: value passed to the open64_file_func callback. Chris@4: Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path Chris@4: is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* Chris@4: does not describe the reality Chris@4: */ Chris@4: Chris@4: Chris@4: extern unzFile ZEXPORT unzOpen2 OF((const char *path, Chris@4: zlib_filefunc_def* pzlib_filefunc_def)); Chris@4: /* Chris@4: Open a Zip file, like unzOpen, but provide a set of file low level API Chris@4: for read/write the zip file (see ioapi.h) Chris@4: */ Chris@4: Chris@4: extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, Chris@4: zlib_filefunc64_def* pzlib_filefunc_def)); Chris@4: /* Chris@4: Open a Zip file, like unz64Open, but provide a set of file low level API Chris@4: for read/write the zip file (see ioapi.h) Chris@4: */ Chris@4: Chris@4: extern int ZEXPORT unzClose OF((unzFile file)); Chris@4: /* Chris@4: Close a ZipFile opened with unzipOpen. Chris@4: If there is files inside the .Zip opened with unzOpenCurrentFile (see later), Chris@4: these files MUST be closed with unzipCloseCurrentFile before call unzipClose. Chris@4: return UNZ_OK if there is no problem. */ Chris@4: Chris@4: extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, Chris@4: unz_global_info *pglobal_info)); Chris@4: Chris@4: extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, Chris@4: unz_global_info64 *pglobal_info)); Chris@4: /* Chris@4: Write info about the ZipFile in the *pglobal_info structure. Chris@4: No preparation of the structure is needed Chris@4: return UNZ_OK if there is no problem. */ Chris@4: Chris@4: Chris@4: extern int ZEXPORT unzGetGlobalComment OF((unzFile file, Chris@4: char *szComment, Chris@4: uLong uSizeBuf)); Chris@4: /* Chris@4: Get the global comment string of the ZipFile, in the szComment buffer. Chris@4: uSizeBuf is the size of the szComment buffer. Chris@4: return the number of byte copied or an error code <0 Chris@4: */ Chris@4: Chris@4: Chris@4: /***************************************************************************/ Chris@4: /* Unzip package allow you browse the directory of the zipfile */ Chris@4: Chris@4: extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); Chris@4: /* Chris@4: Set the current file of the zipfile to the first file. Chris@4: return UNZ_OK if there is no problem Chris@4: */ Chris@4: Chris@4: extern int ZEXPORT unzGoToNextFile OF((unzFile file)); Chris@4: /* Chris@4: Set the current file of the zipfile to the next file. Chris@4: return UNZ_OK if there is no problem Chris@4: return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. Chris@4: */ Chris@4: Chris@4: extern int ZEXPORT unzLocateFile OF((unzFile file, Chris@4: const char *szFileName, Chris@4: int iCaseSensitivity)); Chris@4: /* Chris@4: Try locate the file szFileName in the zipfile. Chris@4: For the iCaseSensitivity signification, see unzStringFileNameCompare Chris@4: Chris@4: return value : Chris@4: UNZ_OK if the file is found. It becomes the current file. Chris@4: UNZ_END_OF_LIST_OF_FILE if the file is not found Chris@4: */ Chris@4: Chris@4: Chris@4: /* ****************************************** */ Chris@4: /* Ryan supplied functions */ Chris@4: /* unz_file_info contain information about a file in the zipfile */ Chris@4: typedef struct unz_file_pos_s Chris@4: { Chris@4: uLong pos_in_zip_directory; /* offset in zip file directory */ Chris@4: uLong num_of_file; /* # of file */ Chris@4: } unz_file_pos; Chris@4: Chris@4: extern int ZEXPORT unzGetFilePos( Chris@4: unzFile file, Chris@4: unz_file_pos* file_pos); Chris@4: Chris@4: extern int ZEXPORT unzGoToFilePos( Chris@4: unzFile file, Chris@4: unz_file_pos* file_pos); Chris@4: Chris@4: typedef struct unz64_file_pos_s Chris@4: { Chris@4: ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ Chris@4: ZPOS64_T num_of_file; /* # of file */ Chris@4: } unz64_file_pos; Chris@4: Chris@4: extern int ZEXPORT unzGetFilePos64( Chris@4: unzFile file, Chris@4: unz64_file_pos* file_pos); Chris@4: Chris@4: extern int ZEXPORT unzGoToFilePos64( Chris@4: unzFile file, Chris@4: const unz64_file_pos* file_pos); Chris@4: Chris@4: /* ****************************************** */ Chris@4: Chris@4: extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, Chris@4: unz_file_info64 *pfile_info, Chris@4: char *szFileName, Chris@4: uLong fileNameBufferSize, Chris@4: void *extraField, Chris@4: uLong extraFieldBufferSize, Chris@4: char *szComment, Chris@4: uLong commentBufferSize)); Chris@4: Chris@4: extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, Chris@4: unz_file_info *pfile_info, Chris@4: char *szFileName, Chris@4: uLong fileNameBufferSize, Chris@4: void *extraField, Chris@4: uLong extraFieldBufferSize, Chris@4: char *szComment, Chris@4: uLong commentBufferSize)); Chris@4: /* Chris@4: Get Info about the current file Chris@4: if pfile_info!=NULL, the *pfile_info structure will contain somes info about Chris@4: the current file Chris@4: if szFileName!=NULL, the filemane string will be copied in szFileName Chris@4: (fileNameBufferSize is the size of the buffer) Chris@4: if extraField!=NULL, the extra field information will be copied in extraField Chris@4: (extraFieldBufferSize is the size of the buffer). Chris@4: This is the Central-header version of the extra field Chris@4: if szComment!=NULL, the comment string of the file will be copied in szComment Chris@4: (commentBufferSize is the size of the buffer) Chris@4: */ Chris@4: Chris@4: Chris@4: /** Addition for GDAL : START */ Chris@4: Chris@4: extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); Chris@4: Chris@4: /** Addition for GDAL : END */ Chris@4: Chris@4: Chris@4: /***************************************************************************/ Chris@4: /* for reading the content of the current zipfile, you can open it, read data Chris@4: from it, and close it (you can close it before reading all the file) Chris@4: */ Chris@4: Chris@4: extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); Chris@4: /* Chris@4: Open for reading data the current file in the zipfile. Chris@4: If there is no error, the return value is UNZ_OK. Chris@4: */ Chris@4: Chris@4: extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, Chris@4: const char* password)); Chris@4: /* Chris@4: Open for reading data the current file in the zipfile. Chris@4: password is a crypting password Chris@4: If there is no error, the return value is UNZ_OK. Chris@4: */ Chris@4: Chris@4: extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, Chris@4: int* method, Chris@4: int* level, Chris@4: int raw)); Chris@4: /* Chris@4: Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) Chris@4: if raw==1 Chris@4: *method will receive method of compression, *level will receive level of Chris@4: compression Chris@4: note : you can set level parameter as NULL (if you did not want known level, Chris@4: but you CANNOT set method parameter as NULL Chris@4: */ Chris@4: Chris@4: extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, Chris@4: int* method, Chris@4: int* level, Chris@4: int raw, Chris@4: const char* password)); Chris@4: /* Chris@4: Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) Chris@4: if raw==1 Chris@4: *method will receive method of compression, *level will receive level of Chris@4: compression Chris@4: note : you can set level parameter as NULL (if you did not want known level, Chris@4: but you CANNOT set method parameter as NULL Chris@4: */ Chris@4: Chris@4: Chris@4: extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); Chris@4: /* Chris@4: Close the file in zip opened with unzOpenCurrentFile Chris@4: Return UNZ_CRCERROR if all the file was read but the CRC is not good Chris@4: */ Chris@4: Chris@4: extern int ZEXPORT unzReadCurrentFile OF((unzFile file, Chris@4: voidp buf, Chris@4: unsigned len)); Chris@4: /* Chris@4: Read bytes from the current file (opened by unzOpenCurrentFile) Chris@4: buf contain buffer where data must be copied Chris@4: len the size of buf. Chris@4: Chris@4: return the number of byte copied if somes bytes are copied Chris@4: return 0 if the end of file was reached Chris@4: return <0 with error code if there is an error Chris@4: (UNZ_ERRNO for IO error, or zLib error for uncompress error) Chris@4: */ Chris@4: Chris@4: extern z_off_t ZEXPORT unztell OF((unzFile file)); Chris@4: Chris@4: extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); Chris@4: /* Chris@4: Give the current position in uncompressed data Chris@4: */ Chris@4: Chris@4: extern int ZEXPORT unzeof OF((unzFile file)); Chris@4: /* Chris@4: return 1 if the end of file was reached, 0 elsewhere Chris@4: */ Chris@4: Chris@4: extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, Chris@4: voidp buf, Chris@4: unsigned len)); Chris@4: /* Chris@4: Read extra field from the current file (opened by unzOpenCurrentFile) Chris@4: This is the local-header version of the extra field (sometimes, there is Chris@4: more info in the local-header version than in the central-header) Chris@4: Chris@4: if buf==NULL, it return the size of the local extra field Chris@4: Chris@4: if buf!=NULL, len is the size of the buffer, the extra header is copied in Chris@4: buf. Chris@4: the return value is the number of bytes copied in buf, or (if <0) Chris@4: the error code Chris@4: */ Chris@4: Chris@4: /***************************************************************************/ Chris@4: Chris@4: /* Get the current file offset */ Chris@4: extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); Chris@4: extern uLong ZEXPORT unzGetOffset (unzFile file); Chris@4: Chris@4: /* Set the current file offset */ Chris@4: extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); Chris@4: extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); Chris@4: Chris@4: Chris@4: Chris@4: #ifdef __cplusplus Chris@4: } Chris@4: #endif Chris@4: Chris@4: #endif /* _unz64_H */