cpl_minizip_zip.h 9.5 KB

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