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