/* unzip.h -- IO for uncompress .zip files using zlib1Version 1.1, February 14h, 20102part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )34Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )56Modifications of Unzip for Zip647Copyright (C) 2007-2008 Even Rouault89Modifications for Zip64 support on both zip and unzip10Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )1112For more info read MiniZip_info.txt1314---------------------------------------------------------------------------------1516Condition of use and distribution are the same than zlib :1718This software is provided 'as-is', without any express or implied19warranty. In no event will the authors be held liable for any damages20arising from the use of this software.2122Permission is granted to anyone to use this software for any purpose,23including commercial applications, and to alter it and redistribute it24freely, subject to the following restrictions:25261. The origin of this software must not be misrepresented; you must not27claim that you wrote the original software. If you use this software28in a product, an acknowledgment in the product documentation would be29appreciated but is not required.302. Altered source versions must be plainly marked as such, and must not be31misrepresented as being the original software.323. This notice may not be removed or altered from any source distribution.3334---------------------------------------------------------------------------------3536Changes3738See header of unzip64.c3940*/4142#ifndef _unz64_H43#define _unz64_H4445#ifdef __cplusplus46extern "C" {47#endif4849#ifndef _ZLIB_H50#include "zlib.h"51#endif5253#ifndef _ZLIBIOAPI_H54#include "ioapi.h"55#endif5657#ifdef HAVE_BZIP258#include "bzlib.h"59#endif6061#define Z_BZIP2ED 126263#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)64/* like the STRICT of WIN32, we define a pointer that cannot be converted65from (void*) without cast */66typedef struct TagunzFile__ { int unused; } unzFile__;67typedef unzFile__ *unzFile;68#else69typedef voidp unzFile;70#endif717273#define UNZ_OK (0)74#define UNZ_END_OF_LIST_OF_FILE (-100)75#define UNZ_ERRNO (Z_ERRNO)76#define UNZ_EOF (0)77#define UNZ_PARAMERROR (-102)78#define UNZ_BADZIPFILE (-103)79#define UNZ_INTERNALERROR (-104)80#define UNZ_CRCERROR (-105)8182/* tm_unz contain date/time info */83typedef struct tm_unz_s84{85int tm_sec; /* seconds after the minute - [0,59] */86int tm_min; /* minutes after the hour - [0,59] */87int tm_hour; /* hours since midnight - [0,23] */88int tm_mday; /* day of the month - [1,31] */89int tm_mon; /* months since January - [0,11] */90int tm_year; /* years - [1980..2044] */91} tm_unz;9293/* unz_global_info structure contain global data about the ZIPfile94These data comes from the end of central dir */95typedef struct unz_global_info64_s96{97ZPOS64_T number_entry; /* total number of entries in98the central dir on this disk */99uLong size_comment; /* size of the global comment of the zipfile */100} unz_global_info64;101102typedef struct unz_global_info_s103{104uLong number_entry; /* total number of entries in105the central dir on this disk */106uLong size_comment; /* size of the global comment of the zipfile */107} unz_global_info;108109/* unz_file_info contain information about a file in the zipfile */110typedef struct unz_file_info64_s111{112uLong version; /* version made by 2 bytes */113uLong version_needed; /* version needed to extract 2 bytes */114uLong flag; /* general purpose bit flag 2 bytes */115uLong compression_method; /* compression method 2 bytes */116uLong dosDate; /* last mod file date in Dos fmt 4 bytes */117uLong crc; /* crc-32 4 bytes */118ZPOS64_T compressed_size; /* compressed size 8 bytes */119ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */120uLong size_filename; /* filename length 2 bytes */121uLong size_file_extra; /* extra field length 2 bytes */122uLong size_file_comment; /* file comment length 2 bytes */123124uLong disk_num_start; /* disk number start 2 bytes */125uLong internal_fa; /* internal file attributes 2 bytes */126uLong external_fa; /* external file attributes 4 bytes */127128tm_unz tmu_date;129} unz_file_info64;130131typedef struct unz_file_info_s132{133uLong version; /* version made by 2 bytes */134uLong version_needed; /* version needed to extract 2 bytes */135uLong flag; /* general purpose bit flag 2 bytes */136uLong compression_method; /* compression method 2 bytes */137uLong dosDate; /* last mod file date in Dos fmt 4 bytes */138uLong crc; /* crc-32 4 bytes */139uLong compressed_size; /* compressed size 4 bytes */140uLong uncompressed_size; /* uncompressed size 4 bytes */141uLong size_filename; /* filename length 2 bytes */142uLong size_file_extra; /* extra field length 2 bytes */143uLong size_file_comment; /* file comment length 2 bytes */144145uLong disk_num_start; /* disk number start 2 bytes */146uLong internal_fa; /* internal file attributes 2 bytes */147uLong external_fa; /* external file attributes 4 bytes */148149tm_unz tmu_date;150} unz_file_info;151152extern int ZEXPORT unzStringFileNameCompare(const char* fileName1,153const char* fileName2,154int iCaseSensitivity);155/*156Compare two filenames (fileName1,fileName2).157If iCaseSensitivity = 1, comparison is case sensitive (like strcmp)158If iCaseSensitivity = 2, comparison is not case sensitive (like strcmpi159or strcasecmp)160If iCaseSensitivity = 0, case sensitivity is default of your operating system161(like 1 on Unix, 2 on Windows)162*/163164165extern unzFile ZEXPORT unzOpen(const char *path);166extern unzFile ZEXPORT unzOpen64(const void *path);167/*168Open a Zip file. path contain the full pathname (by example,169on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer170"zlib/zlib113.zip".171If the zipfile cannot be opened (file don't exist or in not valid), the172return value is NULL.173Else, the return value is a unzFile Handle, usable with other function174of this unzip package.175the "64" function take a const void* pointer, because the path is just the176value passed to the open64_file_func callback.177Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path178is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*179does not describe the reality180*/181182183extern unzFile ZEXPORT unzOpen2(const char *path,184zlib_filefunc_def* pzlib_filefunc_def);185/*186Open a Zip file, like unzOpen, but provide a set of file low level API187for read/write the zip file (see ioapi.h)188*/189190extern unzFile ZEXPORT unzOpen2_64(const void *path,191zlib_filefunc64_def* pzlib_filefunc_def);192/*193Open a Zip file, like unz64Open, but provide a set of file low level API194for read/write the zip file (see ioapi.h)195*/196197extern int ZEXPORT unzClose(unzFile file);198/*199Close a ZipFile opened with unzOpen.200If there is files inside the .Zip opened with unzOpenCurrentFile (see later),201these files MUST be closed with unzCloseCurrentFile before call unzClose.202return UNZ_OK if there is no problem. */203204extern void* unzGetOpaque(unzFile file);205206extern int ZEXPORT unzGetGlobalInfo(unzFile file,207unz_global_info *pglobal_info);208209extern int ZEXPORT unzGetGlobalInfo64(unzFile file,210unz_global_info64 *pglobal_info);211/*212Write info about the ZipFile in the *pglobal_info structure.213No preparation of the structure is needed214return UNZ_OK if there is no problem. */215216217extern int ZEXPORT unzGetGlobalComment(unzFile file,218char *szComment,219uLong uSizeBuf);220/*221Get the global comment string of the ZipFile, in the szComment buffer.222uSizeBuf is the size of the szComment buffer.223return the number of byte copied or an error code <0224*/225226227/***************************************************************************/228/* Unzip package allow you browse the directory of the zipfile */229230extern int ZEXPORT unzGoToFirstFile(unzFile file);231/*232Set the current file of the zipfile to the first file.233return UNZ_OK if there is no problem234*/235236extern int ZEXPORT unzGoToNextFile(unzFile file);237/*238Set the current file of the zipfile to the next file.239return UNZ_OK if there is no problem240return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.241*/242243extern int ZEXPORT unzLocateFile(unzFile file,244const char *szFileName,245int iCaseSensitivity);246/*247Try locate the file szFileName in the zipfile.248For the iCaseSensitivity signification, see unzStringFileNameCompare249250return value :251UNZ_OK if the file is found. It becomes the current file.252UNZ_END_OF_LIST_OF_FILE if the file is not found253*/254255256/* ****************************************** */257/* Ryan supplied functions */258/* unz_file_info contain information about a file in the zipfile */259typedef struct unz_file_pos_s260{261uLong pos_in_zip_directory; /* offset in zip file directory */262uLong num_of_file; /* # of file */263} unz_file_pos;264265extern int ZEXPORT unzGetFilePos(266unzFile file,267unz_file_pos* file_pos);268269extern int ZEXPORT unzGoToFilePos(270unzFile file,271unz_file_pos* file_pos);272273typedef struct unz64_file_pos_s274{275ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */276ZPOS64_T num_of_file; /* # of file */277} unz64_file_pos;278279extern int ZEXPORT unzGetFilePos64(280unzFile file,281unz64_file_pos* file_pos);282283extern int ZEXPORT unzGoToFilePos64(284unzFile file,285const unz64_file_pos* file_pos);286287/* ****************************************** */288289extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file,290unz_file_info64 *pfile_info,291char *szFileName,292uLong fileNameBufferSize,293void *extraField,294uLong extraFieldBufferSize,295char *szComment,296uLong commentBufferSize);297298extern int ZEXPORT unzGetCurrentFileInfo(unzFile file,299unz_file_info *pfile_info,300char *szFileName,301uLong fileNameBufferSize,302void *extraField,303uLong extraFieldBufferSize,304char *szComment,305uLong commentBufferSize);306/*307Get Info about the current file308if pfile_info!=NULL, the *pfile_info structure will contain some info about309the current file310if szFileName!=NULL, the filename string will be copied in szFileName311(fileNameBufferSize is the size of the buffer)312if extraField!=NULL, the extra field information will be copied in extraField313(extraFieldBufferSize is the size of the buffer).314This is the Central-header version of the extra field315if szComment!=NULL, the comment string of the file will be copied in szComment316(commentBufferSize is the size of the buffer)317The file name and comment will be zero-terminated if there is room in the318provided buffer. Otherwise the buffer will contain as much as will fit. If at319least 65537 bytes of room is provided, then the result will always be320complete and zero-terminated.321*/322323324/** Addition for GDAL : START */325326extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file);327328/** Addition for GDAL : END */329330331/***************************************************************************/332/* for reading the content of the current zipfile, you can open it, read data333from it, and close it (you can close it before reading all the file)334*/335336extern int ZEXPORT unzOpenCurrentFile(unzFile file);337/*338Open for reading data the current file in the zipfile.339If there is no error, the return value is UNZ_OK.340*/341342extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file,343const char* password);344/*345Open for reading data the current file in the zipfile.346password is a crypting password347If there is no error, the return value is UNZ_OK.348*/349350extern int ZEXPORT unzOpenCurrentFile2(unzFile file,351int* method,352int* level,353int raw);354/*355Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)356if raw==1357*method will receive method of compression, *level will receive level of358compression359note : you can set level parameter as NULL (if you did not want known level,360but you CANNOT set method parameter as NULL361*/362363extern int ZEXPORT unzOpenCurrentFile3(unzFile file,364int* method,365int* level,366int raw,367const char* password);368/*369Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)370if raw==1371*method will receive method of compression, *level will receive level of372compression373note : you can set level parameter as NULL (if you did not want known level,374but you CANNOT set method parameter as NULL375*/376377378extern int ZEXPORT unzCloseCurrentFile(unzFile file);379/*380Close the file in zip opened with unzOpenCurrentFile381Return UNZ_CRCERROR if all the file was read but the CRC is not good382*/383384extern int ZEXPORT unzReadCurrentFile(unzFile file,385voidp buf,386unsigned len);387/*388Read bytes from the current file (opened by unzOpenCurrentFile)389buf contain buffer where data must be copied390len the size of buf.391392return the number of byte copied if some bytes are copied393return 0 if the end of file was reached394return <0 with error code if there is an error395(UNZ_ERRNO for IO error, or zLib error for uncompress error)396*/397398extern int ZEXPORT unzSeekCurrentFile(unzFile file, int pos);399/*400Seek to position in uncompressed data401*/402403extern z_off_t ZEXPORT unztell(unzFile file);404405extern ZPOS64_T ZEXPORT unztell64(unzFile file);406/*407Give the current position in uncompressed data408*/409410extern int ZEXPORT unzeof(unzFile file);411/*412return 1 if the end of file was reached, 0 elsewhere413*/414415extern int ZEXPORT unzGetLocalExtrafield(unzFile file,416voidp buf,417unsigned len);418/*419Read extra field from the current file (opened by unzOpenCurrentFile)420This is the local-header version of the extra field (sometimes, there is421more info in the local-header version than in the central-header)422423if buf==NULL, it return the size of the local extra field424425if buf!=NULL, len is the size of the buffer, the extra header is copied in426buf.427the return value is the number of bytes copied in buf, or (if <0)428the error code429*/430431/***************************************************************************/432433/* Get the current file offset */434extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);435extern uLong ZEXPORT unzGetOffset (unzFile file);436437/* Set the current file offset */438extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);439extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);440441442443#ifdef __cplusplus444}445#endif446447#endif /* _unz64_H */448449450