/* 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{85uInt tm_sec; /* seconds after the minute - [0,59] */86uInt tm_min; /* minutes after the hour - [0,59] */87uInt tm_hour; /* hours since midnight - [0,23] */88uInt tm_mday; /* day of the month - [1,31] */89uInt tm_mon; /* months since January - [0,11] */90uInt 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 OF ((const char* fileName1,153const char* fileName2,154int iCaseSensitivity));155/*156Compare two filename (fileName1,fileName2).157If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)158If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi159or strcasecmp)160If iCaseSenisivity = 0, case sensitivity is defaut of your operating system161(like 1 on Unix, 2 on Windows)162*/163164165extern unzFile ZEXPORT unzOpen OF((const char *path));166extern unzFile ZEXPORT unzOpen64 OF((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 OF((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 OF((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 OF((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 int ZEXPORT unzGetGlobalInfo OF((unzFile file,205unz_global_info *pglobal_info));206207extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,208unz_global_info64 *pglobal_info));209/*210Write info about the ZipFile in the *pglobal_info structure.211No preparation of the structure is needed212return UNZ_OK if there is no problem. */213214215extern int ZEXPORT unzGetGlobalComment OF((unzFile file,216char *szComment,217uLong uSizeBuf));218/*219Get the global comment string of the ZipFile, in the szComment buffer.220uSizeBuf is the size of the szComment buffer.221return the number of byte copied or an error code <0222*/223224225/***************************************************************************/226/* Unzip package allow you browse the directory of the zipfile */227228extern int ZEXPORT unzGoToFirstFile OF((unzFile file));229/*230Set the current file of the zipfile to the first file.231return UNZ_OK if there is no problem232*/233234extern int ZEXPORT unzGoToNextFile OF((unzFile file));235/*236Set the current file of the zipfile to the next file.237return UNZ_OK if there is no problem238return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.239*/240241extern int ZEXPORT unzLocateFile OF((unzFile file,242const char *szFileName,243int iCaseSensitivity));244/*245Try locate the file szFileName in the zipfile.246For the iCaseSensitivity signification, see unzStringFileNameCompare247248return value :249UNZ_OK if the file is found. It becomes the current file.250UNZ_END_OF_LIST_OF_FILE if the file is not found251*/252253254/* ****************************************** */255/* Ryan supplied functions */256/* unz_file_info contain information about a file in the zipfile */257typedef struct unz_file_pos_s258{259uLong pos_in_zip_directory; /* offset in zip file directory */260uLong num_of_file; /* # of file */261} unz_file_pos;262263extern int ZEXPORT unzGetFilePos(264unzFile file,265unz_file_pos* file_pos);266267extern int ZEXPORT unzGoToFilePos(268unzFile file,269unz_file_pos* file_pos);270271typedef struct unz64_file_pos_s272{273ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */274ZPOS64_T num_of_file; /* # of file */275} unz64_file_pos;276277extern int ZEXPORT unzGetFilePos64(278unzFile file,279unz64_file_pos* file_pos);280281extern int ZEXPORT unzGoToFilePos64(282unzFile file,283const unz64_file_pos* file_pos);284285/* ****************************************** */286287extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,288unz_file_info64 *pfile_info,289char *szFileName,290uLong fileNameBufferSize,291void *extraField,292uLong extraFieldBufferSize,293char *szComment,294uLong commentBufferSize));295296extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,297unz_file_info *pfile_info,298char *szFileName,299uLong fileNameBufferSize,300void *extraField,301uLong extraFieldBufferSize,302char *szComment,303uLong commentBufferSize));304/*305Get Info about the current file306if pfile_info!=NULL, the *pfile_info structure will contain somes info about307the current file308if szFileName!=NULL, the filemane string will be copied in szFileName309(fileNameBufferSize is the size of the buffer)310if extraField!=NULL, the extra field information will be copied in extraField311(extraFieldBufferSize is the size of the buffer).312This is the Central-header version of the extra field313if szComment!=NULL, the comment string of the file will be copied in szComment314(commentBufferSize is the size of the buffer)315*/316317318/** Addition for GDAL : START */319320extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));321322/** Addition for GDAL : END */323324325/***************************************************************************/326/* for reading the content of the current zipfile, you can open it, read data327from it, and close it (you can close it before reading all the file)328*/329330extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));331/*332Open for reading data the current file in the zipfile.333If there is no error, the return value is UNZ_OK.334*/335336extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,337const char* password));338/*339Open for reading data the current file in the zipfile.340password is a crypting password341If there is no error, the return value is UNZ_OK.342*/343344extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,345int* method,346int* level,347int raw));348/*349Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)350if raw==1351*method will receive method of compression, *level will receive level of352compression353note : you can set level parameter as NULL (if you did not want known level,354but you CANNOT set method parameter as NULL355*/356357extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,358int* method,359int* level,360int raw,361const char* password));362/*363Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)364if raw==1365*method will receive method of compression, *level will receive level of366compression367note : you can set level parameter as NULL (if you did not want known level,368but you CANNOT set method parameter as NULL369*/370371372extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));373/*374Close the file in zip opened with unzOpenCurrentFile375Return UNZ_CRCERROR if all the file was read but the CRC is not good376*/377378extern int ZEXPORT unzReadCurrentFile OF((unzFile file,379voidp buf,380unsigned len));381/*382Read bytes from the current file (opened by unzOpenCurrentFile)383buf contain buffer where data must be copied384len the size of buf.385386return the number of byte copied if somes bytes are copied387return 0 if the end of file was reached388return <0 with error code if there is an error389(UNZ_ERRNO for IO error, or zLib error for uncompress error)390*/391392extern z_off_t ZEXPORT unztell OF((unzFile file));393394extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));395/*396Give the current position in uncompressed data397*/398399extern int ZEXPORT unzeof OF((unzFile file));400/*401return 1 if the end of file was reached, 0 elsewhere402*/403404extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,405voidp buf,406unsigned len));407/*408Read extra field from the current file (opened by unzOpenCurrentFile)409This is the local-header version of the extra field (sometimes, there is410more info in the local-header version than in the central-header)411412if buf==NULL, it return the size of the local extra field413414if buf!=NULL, len is the size of the buffer, the extra header is copied in415buf.416the return value is the number of bytes copied in buf, or (if <0)417the error code418*/419420/***************************************************************************/421422/* Get the current file offset */423extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);424extern uLong ZEXPORT unzGetOffset (unzFile file);425426/* Set the current file offset */427extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);428extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);429430431432#ifdef __cplusplus433}434#endif435436#endif /* _unz64_H */437438439