Home | History | Annotate | Download | only in minizip
      1 /* zip.h -- IO for compress .zip files using zlib
      2    Version 1.01e, February 12th, 2005
      3 
      4    Copyright (C) 1998-2005 Gilles Vollant
      5 
      6    This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
      7      WinZip, InfoZip tools and compatible.
      8    Multi volume ZipFile (span) are not supported.
      9    Encryption compatible with pkzip 2.04g only supported
     10    Old compressions used by old PKZip 1.x are not supported
     11 
     12   For uncompress .zip file, look at unzip.h
     13 
     14 
     15    I WAIT FEEDBACK at mail info (at) winimage.com
     16    Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
     17 
     18    Condition of use and distribution are the same than zlib :
     19 
     20   This software is provided 'as-is', without any express or implied
     21   warranty.  In no event will the authors be held liable for any damages
     22   arising from the use of this software.
     23 
     24   Permission is granted to anyone to use this software for any purpose,
     25   including commercial applications, and to alter it and redistribute it
     26   freely, subject to the following restrictions:
     27 
     28   1. The origin of this software must not be misrepresented; you must not
     29      claim that you wrote the original software. If you use this software
     30      in a product, an acknowledgment in the product documentation would be
     31      appreciated but is not required.
     32   2. Altered source versions must be plainly marked as such, and must not be
     33      misrepresented as being the original software.
     34   3. This notice may not be removed or altered from any source distribution.
     35 
     36 
     37 */
     38 
     39 /* for more info about .ZIP format, see
     40       http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
     41       http://www.info-zip.org/pub/infozip/doc/
     42    PkWare has also a specification at :
     43       ftp://ftp.pkware.com/probdesc.zip
     44 */
     45 
     46 #ifndef _zip_H
     47 #define _zip_H
     48 
     49 #ifdef __cplusplus
     50 extern "C" {
     51 #endif
     52 
     53 #if defined(USE_SYSTEM_ZLIB)
     54 #include <zlib.h>
     55 #else
     56 #include "third_party/zlib/zlib.h"
     57 #endif
     58 
     59 #ifndef _ZLIBIOAPI_H
     60 #include "ioapi.h"
     61 #endif
     62 
     63 #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
     64 /* like the STRICT of WIN32, we define a pointer that cannot be converted
     65     from (void*) without cast */
     66 typedef struct TagzipFile__ { int unused; } zipFile__;
     67 typedef zipFile__ *zipFile;
     68 #else
     69 typedef voidp zipFile;
     70 #endif
     71 
     72 #define ZIP_OK                          (0)
     73 #define ZIP_EOF                         (0)
     74 #define ZIP_ERRNO                       (Z_ERRNO)
     75 #define ZIP_PARAMERROR                  (-102)
     76 #define ZIP_BADZIPFILE                  (-103)
     77 #define ZIP_INTERNALERROR               (-104)
     78 
     79 #ifndef DEF_MEM_LEVEL
     80 #  if MAX_MEM_LEVEL >= 8
     81 #    define DEF_MEM_LEVEL 8
     82 #  else
     83 #    define DEF_MEM_LEVEL  MAX_MEM_LEVEL
     84 #  endif
     85 #endif
     86 /* default memLevel */
     87 
     88 /* tm_zip contain date/time info */
     89 typedef struct tm_zip_s
     90 {
     91     uInt tm_sec;            /* seconds after the minute - [0,59] */
     92     uInt tm_min;            /* minutes after the hour - [0,59] */
     93     uInt tm_hour;           /* hours since midnight - [0,23] */
     94     uInt tm_mday;           /* day of the month - [1,31] */
     95     uInt tm_mon;            /* months since January - [0,11] */
     96     uInt tm_year;           /* years - [1980..2044] */
     97 } tm_zip;
     98 
     99 typedef struct
    100 {
    101     tm_zip      tmz_date;       /* date in understandable format           */
    102     uLong       dosDate;       /* if dos_date == 0, tmu_date is used      */
    103 /*    uLong       flag;        */   /* general purpose bit flag        2 bytes */
    104 
    105     uLong       internal_fa;    /* internal file attributes        2 bytes */
    106     uLong       external_fa;    /* external file attributes        4 bytes */
    107 } zip_fileinfo;
    108 
    109 typedef const char* zipcharpc;
    110 
    111 
    112 #define APPEND_STATUS_CREATE        (0)
    113 #define APPEND_STATUS_CREATEAFTER   (1)
    114 #define APPEND_STATUS_ADDINZIP      (2)
    115 
    116 extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
    117 /*
    118   Create a zipfile.
    119      pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
    120        an Unix computer "zlib/zlib113.zip".
    121      if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
    122        will be created at the end of the file.
    123          (useful if the file contain a self extractor code)
    124      if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
    125        add files in existing zip (be sure you don't add file that doesn't exist)
    126      If the zipfile cannot be opened, the return value is NULL.
    127      Else, the return value is a zipFile Handle, usable with other function
    128        of this zip package.
    129 */
    130 
    131 /* Note : there is no delete function into a zipfile.
    132    If you want delete file into a zipfile, you must open a zipfile, and create another
    133    Of couse, you can use RAW reading and writing to copy the file you did not want delte
    134 */
    135 
    136 extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
    137                                    int append,
    138                                    zipcharpc* globalcomment,
    139                                    zlib_filefunc_def* pzlib_filefunc_def));
    140 
    141 extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
    142                        const char* filename,
    143                        const zip_fileinfo* zipfi,
    144                        const void* extrafield_local,
    145                        uInt size_extrafield_local,
    146                        const void* extrafield_global,
    147                        uInt size_extrafield_global,
    148                        const char* comment,
    149                        int method,
    150                        int level));
    151 /*
    152   Open a file in the ZIP for writing.
    153   filename : the filename in zip (if NULL, '-' without quote will be used
    154   *zipfi contain supplemental information
    155   if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
    156     contains the extrafield data the the local header
    157   if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
    158     contains the extrafield data the the local header
    159   if comment != NULL, comment contain the comment string
    160   method contain the compression method (0 for store, Z_DEFLATED for deflate)
    161   level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
    162 */
    163 
    164 
    165 extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
    166                                             const char* filename,
    167                                             const zip_fileinfo* zipfi,
    168                                             const void* extrafield_local,
    169                                             uInt size_extrafield_local,
    170                                             const void* extrafield_global,
    171                                             uInt size_extrafield_global,
    172                                             const char* comment,
    173                                             int method,
    174                                             int level,
    175                                             int raw));
    176 
    177 /*
    178   Same than zipOpenNewFileInZip, except if raw=1, we write raw file
    179  */
    180 
    181 extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
    182                                             const char* filename,
    183                                             const zip_fileinfo* zipfi,
    184                                             const void* extrafield_local,
    185                                             uInt size_extrafield_local,
    186                                             const void* extrafield_global,
    187                                             uInt size_extrafield_global,
    188                                             const char* comment,
    189                                             int method,
    190                                             int level,
    191                                             int raw,
    192                                             int windowBits,
    193                                             int memLevel,
    194                                             int strategy,
    195                                             const char* password,
    196                                             uLong crcForCtypting));
    197 
    198 /*
    199   Same than zipOpenNewFileInZip2, except
    200     windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
    201     password : crypting password (NULL for no crypting)
    202     crcForCtypting : crc of file to compress (needed for crypting)
    203  */
    204 
    205 
    206 extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
    207                        const void* buf,
    208                        unsigned len));
    209 /*
    210   Write data in the zipfile
    211 */
    212 
    213 extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
    214 /*
    215   Close the current file in the zipfile
    216 */
    217 
    218 extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
    219                                             uLong uncompressed_size,
    220                                             uLong crc32));
    221 /*
    222   Close the current file in the zipfile, for fiel opened with
    223     parameter raw=1 in zipOpenNewFileInZip2
    224   uncompressed_size and crc32 are value for the uncompressed size
    225 */
    226 
    227 extern int ZEXPORT zipClose OF((zipFile file,
    228                 const char* global_comment));
    229 /*
    230   Close the zipfile
    231 */
    232 
    233 #ifdef __cplusplus
    234 }
    235 #endif
    236 
    237 #endif /* _zip_H */
    238