zip.h 9.2 KB

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