unzip.h

Go to the documentation of this file.
00001 /* unzip.h -- IO for uncompress .zip files using zlib
00002    Version 1.01, May 8th, 2004
00003 
00004    Copyright (C) 1998-2004 Gilles Vollant
00005    Converted to more modern C/C++ by the Pentagram team.
00006 
00007    This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
00008      WinZip, InfoZip tools and compatible.
00009    Encryption and multi volume ZipFile (span) are not supported.
00010    Old compressions used by old PKZip 1.x are not supported
00011 
00012 
00013    I WAIT FEEDBACK at mail info@winimage.com
00014    Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
00015 
00016    Condition of use and distribution are the same than zlib :
00017 
00018   This software is provided 'as-is', without any express or implied
00019   warranty.  In no event will the authors be held liable for any damages
00020   arising from the use of this software.
00021 
00022   Permission is granted to anyone to use this software for any purpose,
00023   including commercial applications, and to alter it and redistribute it
00024   freely, subject to the following restrictions:
00025 
00026   1. The origin of this software must not be misrepresented; you must not
00027      claim that you wrote the original software. If you use this software
00028      in a product, an acknowledgment in the product documentation would be
00029      appreciated but is not required.
00030   2. Altered source versions must be plainly marked as such, and must not be
00031      misrepresented as being the original software.
00032   3. This notice may not be removed or altered from any source distribution.
00033 
00034 
00035 */
00036 
00037 /* for more info about .ZIP format, see
00038       http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
00039       http://www.info-zip.org/pub/infozip/doc/
00040    PkWare has also a specification at :
00041       ftp://ftp.pkware.com/probdesc.zip
00042 */
00043 
00044 #ifndef _unz_H
00045 #define _unz_H
00046 
00047 #ifndef _ZLIB_H
00048 #include "zlib.h"
00049 #endif
00050 
00051 #ifndef _ZLIBIOAPI_H
00052 #include "ioapi.h"
00053 #endif
00054 
00055 namespace PentZip {
00056 
00057 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
00058 /* like the STRICT of WIN32, we define a pointer that cannot be converted
00059     from (void*) without cast */
00060 typedef struct TagunzFile__ { int unused; } unzFile__;
00061 typedef unzFile__ *unzFile;
00062 #else
00063 typedef voidp unzFile;
00064 #endif
00065 
00066 
00067 #define UNZ_OK                          (0)
00068 #define UNZ_END_OF_LIST_OF_FILE         (-100)
00069 #define UNZ_ERRNO                       (Z_ERRNO)
00070 #define UNZ_EOF                         (0)
00071 #define UNZ_PARAMERROR                  (-102)
00072 #define UNZ_BADZIPFILE                  (-103)
00073 #define UNZ_INTERNALERROR               (-104)
00074 #define UNZ_CRCERROR                    (-105)
00075 
00076 /* tm_unz contain date/time info */
00077 typedef struct tm_unz_s
00078 {
00079     uInt tm_sec;            /* seconds after the minute - [0,59] */
00080     uInt tm_min;            /* minutes after the hour - [0,59] */
00081     uInt tm_hour;           /* hours since midnight - [0,23] */
00082     uInt tm_mday;           /* day of the month - [1,31] */
00083     uInt tm_mon;            /* months since January - [0,11] */
00084     uInt tm_year;           /* years - [1980..2044] */
00085 } tm_unz;
00086 
00087 /* unz_global_info structure contain global data about the ZIPfile
00088    These data comes from the end of central dir */
00089 typedef struct unz_global_info_s
00090 {
00091     uLong number_entry;         /* total number of entries in
00092                        the central dir on this disk */
00093     uLong size_comment;         /* size of the global comment of the zipfile */
00094 } unz_global_info;
00095 
00096 
00097 /* unz_file_info contain information about a file in the zipfile */
00098 typedef struct unz_file_info_s
00099 {
00100     uLong version;              /* version made by                 2 bytes */
00101     uLong version_needed;       /* version needed to extract       2 bytes */
00102     uLong flag;                 /* general purpose bit flag        2 bytes */
00103     uLong compression_method;   /* compression method              2 bytes */
00104     uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
00105     uLong crc;                  /* crc-32                          4 bytes */
00106     uLong compressed_size;      /* compressed size                 4 bytes */
00107     uLong uncompressed_size;    /* uncompressed size               4 bytes */
00108     uLong size_filename;        /* filename length                 2 bytes */
00109     uLong size_file_extra;      /* extra field length              2 bytes */
00110     uLong size_file_comment;    /* file comment length             2 bytes */
00111 
00112     uLong disk_num_start;       /* disk number start               2 bytes */
00113     uLong internal_fa;          /* internal file attributes        2 bytes */
00114     uLong external_fa;          /* external file attributes        4 bytes */
00115 
00116     tm_unz tmu_date;
00117 } unz_file_info;
00118 
00119 extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
00120                                                  const char* fileName2,
00121                                                  int iCaseSensitivity));
00122 /*
00123    Compare two filename (fileName1,fileName2).
00124    If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
00125    If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
00126                                 or strcasecmp)
00127    If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
00128     (like 1 on Unix, 2 on Windows)
00129 */
00130 
00131 
00132 extern unzFile ZEXPORT unzOpen OF((const char *path));
00133 /*
00134   Open a Zip file. path contain the full pathname (by example,
00135      on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
00136      "zlib/zlib113.zip".
00137      If the zipfile cannot be opened (file don't exist or in not valid), the
00138        return value is NULL.
00139      Else, the return value is a unzFile Handle, usable with other function
00140        of this unzip package.
00141 */
00142 
00143 extern unzFile ZEXPORT unzOpen2 OF((const char *path,
00144                                     zlib_filefunc_def* pzlib_filefunc_def));
00145 /*
00146    Open a Zip file, like unzOpen, but provide a set of file low level API
00147       for read/write the zip file (see ioapi.h)
00148 */
00149 
00150 extern int ZEXPORT unzClose OF((unzFile file));
00151 /*
00152   Close a ZipFile opened with unzipOpen.
00153   If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
00154     these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
00155   return UNZ_OK if there is no problem. */
00156 
00157 extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
00158                                         unz_global_info *pglobal_info));
00159 /*
00160   Write info about the ZipFile in the *pglobal_info structure.
00161   No preparation of the structure is needed
00162   return UNZ_OK if there is no problem. */
00163 
00164 
00165 extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
00166                                            char *szComment,
00167                                            uLong uSizeBuf));
00168 /*
00169   Get the global comment string of the ZipFile, in the szComment buffer.
00170   uSizeBuf is the size of the szComment buffer.
00171   return the number of byte copied or an error code <0
00172 */
00173 
00174 
00175 /***************************************************************************/
00176 /* Unzip package allow you browse the directory of the zipfile */
00177 
00178 extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
00179 /*
00180   Set the current file of the zipfile to the first file.
00181   return UNZ_OK if there is no problem
00182 */
00183 
00184 extern int ZEXPORT unzGoToNextFile OF((unzFile file));
00185 /*
00186   Set the current file of the zipfile to the next file.
00187   return UNZ_OK if there is no problem
00188   return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
00189 */
00190 
00191 extern int ZEXPORT unzLocateFile OF((unzFile file,
00192                      const char *szFileName,
00193                      int iCaseSensitivity));
00194 /*
00195   Try locate the file szFileName in the zipfile.
00196   For the iCaseSensitivity signification, see unzStringFileNameCompare
00197 
00198   return value :
00199   UNZ_OK if the file is found. It becomes the current file.
00200   UNZ_END_OF_LIST_OF_FILE if the file is not found
00201 */
00202 
00203 
00204 /* ****************************************** */
00205 /* Ryan supplied functions */
00206 /* unz_file_info contain information about a file in the zipfile */
00207 typedef struct unz_file_pos_s
00208 {
00209     uLong pos_in_zip_directory;   /* offset in zip file directory */
00210     uLong num_of_file;            /* # of file */
00211 } unz_file_pos;
00212 
00213 extern int ZEXPORT unzGetFilePos(
00214     unzFile file,
00215     unz_file_pos* file_pos);
00216 
00217 extern int ZEXPORT unzGoToFilePos(
00218     unzFile file,
00219     unz_file_pos* file_pos);
00220 
00221 /* ****************************************** */
00222 
00223 extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
00224                          unz_file_info *pfile_info,
00225                          char *szFileName,
00226                          uLong fileNameBufferSize,
00227                          void *extraField,
00228                          uLong extraFieldBufferSize,
00229                          char *szComment,
00230                          uLong commentBufferSize));
00231 /*
00232   Get Info about the current file
00233   if pfile_info!=NULL, the *pfile_info structure will contain somes info about
00234         the current file
00235   if szFileName!=NULL, the filemane string will be copied in szFileName
00236             (fileNameBufferSize is the size of the buffer)
00237   if extraField!=NULL, the extra field information will be copied in extraField
00238             (extraFieldBufferSize is the size of the buffer).
00239             This is the Central-header version of the extra field
00240   if szComment!=NULL, the comment string of the file will be copied in szComment
00241             (commentBufferSize is the size of the buffer)
00242 */
00243 
00244 /***************************************************************************/
00245 /* for reading the content of the current zipfile, you can open it, read data
00246    from it, and close it (you can close it before reading all the file)
00247    */
00248 
00249 extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
00250 /*
00251   Open for reading data the current file in the zipfile.
00252   If there is no error, the return value is UNZ_OK.
00253 */
00254 
00255 extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
00256                                                   const char* password));
00257 /*
00258   Open for reading data the current file in the zipfile.
00259   password is a crypting password
00260   If there is no error, the return value is UNZ_OK.
00261 */
00262 
00263 extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
00264                                            int* method,
00265                                            int* level,
00266                                            int raw));
00267 /*
00268   Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
00269     if raw==1
00270   *method will receive method of compression, *level will receive level of
00271      compression
00272   note : you can set level parameter as NULL (if you did not want known level,
00273          but you CANNOT set method parameter as NULL
00274 */
00275 
00276 extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
00277                                            int* method,
00278                                            int* level,
00279                                            int raw,
00280                                            const char* password));
00281 /*
00282   Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
00283     if raw==1
00284   *method will receive method of compression, *level will receive level of
00285      compression
00286   note : you can set level parameter as NULL (if you did not want known level,
00287          but you CANNOT set method parameter as NULL
00288 */
00289 
00290 
00291 extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
00292 /*
00293   Close the file in zip opened with unzOpenCurrentFile
00294   Return UNZ_CRCERROR if all the file was read but the CRC is not good
00295 */
00296 
00297 extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
00298                       voidp buf,
00299                       unsigned len));
00300 /*
00301   Read bytes from the current file (opened by unzOpenCurrentFile)
00302   buf contain buffer where data must be copied
00303   len the size of buf.
00304 
00305   return the number of byte copied if somes bytes are copied
00306   return 0 if the end of file was reached
00307   return <0 with error code if there is an error
00308     (UNZ_ERRNO for IO error, or zLib error for uncompress error)
00309 */
00310 
00311 extern z_off_t ZEXPORT unztell OF((unzFile file));
00312 /*
00313   Give the current position in uncompressed data
00314 */
00315 
00316 extern int ZEXPORT unzeof OF((unzFile file));
00317 /*
00318   return 1 if the end of file was reached, 0 elsewhere
00319 */
00320 
00321 extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
00322                                              voidp buf,
00323                                              unsigned len));
00324 /*
00325   Read extra field from the current file (opened by unzOpenCurrentFile)
00326   This is the local-header version of the extra field (sometimes, there is
00327     more info in the local-header version than in the central-header)
00328 
00329   if buf==NULL, it return the size of the local extra field
00330 
00331   if buf!=NULL, len is the size of the buffer, the extra header is copied in
00332     buf.
00333   the return value is the number of bytes copied in buf, or (if <0)
00334     the error code
00335 */
00336 
00337 /***************************************************************************/
00338 
00339 /* Get the current file offset */
00340 extern uLong ZEXPORT unzGetOffset (unzFile file);
00341 
00342 /* Set the current file offset */
00343 extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
00344 
00345 
00346 }
00347 
00348 
00349 #endif /* _unz_H */

Generated on Fri Jul 27 22:27:51 2007 for pentagram by  doxygen 1.4.7