unzip.h

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

Generated by  doxygen 1.6.2