zip.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /* zip.h -- IO on .zip files using zlib
  2. Version 1.1, February 14h, 2010
  3. part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
  4. Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
  5. Modifications for Zip64 support
  6. Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
  7. For more info read MiniZip_info.txt
  8. ---------------------------------------------------------------------------
  9. Condition of use and distribution are the same than zlib :
  10. This software is provided 'as-is', without any express or implied
  11. warranty. In no event will the authors be held liable for any damages
  12. arising from the use of this software.
  13. Permission is granted to anyone to use this software for any purpose,
  14. including commercial applications, and to alter it and redistribute it
  15. freely, subject to the following restrictions:
  16. 1. The origin of this software must not be misrepresented; you must not
  17. claim that you wrote the original software. If you use this software
  18. in a product, an acknowledgment in the product documentation would be
  19. appreciated but is not required.
  20. 2. Altered source versions must be plainly marked as such, and must not be
  21. misrepresented as being the original software.
  22. 3. This notice may not be removed or altered from any source distribution.
  23. ---------------------------------------------------------------------------
  24. Changes
  25. See header of zip.h
  26. ---------------------------------------------------------------------------
  27. As per the requirement above, this file is plainly marked as modified
  28. by Sergey A. Tachenov. Most modifications include the I/O API redesign
  29. to support QIODevice interface. Some improvements and small fixes were also made.
  30. */
  31. #ifndef _zip12_H
  32. #define _zip12_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. //#define HAVE_BZIP2
  37. #ifndef _ZLIB_H
  38. #include "zlib.h"
  39. #endif
  40. #ifndef _ZLIBIOAPI_H
  41. #include "ioapi.h"
  42. #endif
  43. #ifdef HAVE_BZIP2
  44. #include "bzlib.h"
  45. #endif
  46. #define Z_BZIP2ED 12
  47. #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
  48. /* like the STRICT of WIN32, we define a pointer that cannot be converted
  49. from (void*) without cast */
  50. typedef struct TagzipFile__ { int unused; } zipFile__;
  51. typedef zipFile__ *zipFile;
  52. #else
  53. typedef voidp zipFile;
  54. #endif
  55. #define ZIP_OK (0)
  56. #define ZIP_EOF (0)
  57. #define ZIP_ERRNO (Z_ERRNO)
  58. #define ZIP_PARAMERROR (-102)
  59. #define ZIP_BADZIPFILE (-103)
  60. #define ZIP_INTERNALERROR (-104)
  61. #define ZIP_WRITE_DATA_DESCRIPTOR 0x8u
  62. #define ZIP_AUTO_CLOSE 0x1u
  63. #define ZIP_SEQUENTIAL 0x2u
  64. #define ZIP_DEFAULT_FLAGS (ZIP_AUTO_CLOSE | ZIP_WRITE_DATA_DESCRIPTOR)
  65. #ifndef DEF_MEM_LEVEL
  66. # if MAX_MEM_LEVEL >= 8
  67. # define DEF_MEM_LEVEL 8
  68. # else
  69. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  70. # endif
  71. #endif
  72. /* default memLevel */
  73. /* tm_zip contain date/time info */
  74. typedef struct tm_zip_s
  75. {
  76. uInt tm_sec; /* seconds after the minute - [0,59] */
  77. uInt tm_min; /* minutes after the hour - [0,59] */
  78. uInt tm_hour; /* hours since midnight - [0,23] */
  79. uInt tm_mday; /* day of the month - [1,31] */
  80. uInt tm_mon; /* months since January - [0,11] */
  81. uInt tm_year; /* years - [1980..2044] */
  82. } tm_zip;
  83. typedef struct
  84. {
  85. tm_zip tmz_date; /* date in understandable format */
  86. uLong dosDate; /* if dos_date == 0, tmu_date is used */
  87. /* uLong flag; */ /* general purpose bit flag 2 bytes */
  88. uLong internal_fa; /* internal file attributes 2 bytes */
  89. uLong external_fa; /* external file attributes 4 bytes */
  90. } zip_fileinfo;
  91. typedef const char* zipcharpc;
  92. #define APPEND_STATUS_CREATE (0)
  93. #define APPEND_STATUS_CREATEAFTER (1)
  94. #define APPEND_STATUS_ADDINZIP (2)
  95. extern zipFile ZEXPORT zipOpen OF((voidpf file, int append));
  96. extern zipFile ZEXPORT zipOpen64 OF((voidpf file, int append));
  97. /*
  98. Create a zipfile.
  99. the file argument depends on the API used, for QuaZIP it's a QIODevice
  100. pointer.
  101. if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
  102. will be created at the end of the file.
  103. (useful if the file contain a self extractor code)
  104. if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
  105. add files in existing zip (be sure you don't add file that doesn't exist)
  106. If the zipfile cannot be opened, the return value is NULL.
  107. Else, the return value is a zipFile Handle, usable with other function
  108. of this zip package.
  109. */
  110. /* Note : there is no delete function into a zipfile.
  111. If you want delete file into a zipfile, you must open a zipfile, and create another
  112. Of couse, you can use RAW reading and writing to copy the file you did not want delte
  113. */
  114. extern zipFile ZEXPORT zipOpen2 OF((voidpf file,
  115. int append,
  116. zipcharpc* globalcomment,
  117. zlib_filefunc_def* pzlib_filefunc_def));
  118. extern zipFile ZEXPORT zipOpen2_64 OF((voidpf file,
  119. int append,
  120. zipcharpc* globalcomment,
  121. zlib_filefunc64_def* pzlib_filefunc_def));
  122. /*
  123. * Exported by Sergey A. Tachenov to suit the needs of QuaZIP.
  124. * Note that this function MAY change signature in order to
  125. * provide new QuaZIP features. You have been warned!
  126. * */
  127. extern zipFile ZEXPORT zipOpen3 (voidpf file,
  128. int append,
  129. zipcharpc* globalcomment,
  130. zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
  131. unsigned flags);
  132. extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
  133. const char* filename,
  134. const zip_fileinfo* zipfi,
  135. const void* extrafield_local,
  136. uInt size_extrafield_local,
  137. const void* extrafield_global,
  138. uInt size_extrafield_global,
  139. const char* comment,
  140. int method,
  141. int level));
  142. extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
  143. const char* filename,
  144. const zip_fileinfo* zipfi,
  145. const void* extrafield_local,
  146. uInt size_extrafield_local,
  147. const void* extrafield_global,
  148. uInt size_extrafield_global,
  149. const char* comment,
  150. int method,
  151. int level,
  152. int zip64));
  153. /*
  154. Open a file in the ZIP for writing.
  155. filename : the filename in zip (if NULL, '-' without quote will be used
  156. *zipfi contain supplemental information
  157. if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
  158. contains the extrafield data the the local header
  159. if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
  160. contains the extrafield data the the local header
  161. if comment != NULL, comment contain the comment string
  162. method contain the compression method (0 for store, Z_DEFLATED for deflate)
  163. level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
  164. zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
  165. this MUST be '1' if the uncompressed size is >= 0xffffffff.
  166. */
  167. extern int ZEXPORT zipOpenNewFileInZip2 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. extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
  179. const char* filename,
  180. const zip_fileinfo* zipfi,
  181. const void* extrafield_local,
  182. uInt size_extrafield_local,
  183. const void* extrafield_global,
  184. uInt size_extrafield_global,
  185. const char* comment,
  186. int method,
  187. int level,
  188. int raw,
  189. int zip64));
  190. /*
  191. Same than zipOpenNewFileInZip, except if raw=1, we write raw file
  192. */
  193. extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
  194. const char* filename,
  195. const zip_fileinfo* zipfi,
  196. const void* extrafield_local,
  197. uInt size_extrafield_local,
  198. const void* extrafield_global,
  199. uInt size_extrafield_global,
  200. const char* comment,
  201. int method,
  202. int level,
  203. int raw,
  204. int windowBits,
  205. int memLevel,
  206. int strategy,
  207. const char* password,
  208. uLong crcForCrypting));
  209. extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
  210. const char* filename,
  211. const zip_fileinfo* zipfi,
  212. const void* extrafield_local,
  213. uInt size_extrafield_local,
  214. const void* extrafield_global,
  215. uInt size_extrafield_global,
  216. const char* comment,
  217. int method,
  218. int level,
  219. int raw,
  220. int windowBits,
  221. int memLevel,
  222. int strategy,
  223. const char* password,
  224. uLong crcForCrypting,
  225. int zip64
  226. ));
  227. /*
  228. Same than zipOpenNewFileInZip2, except
  229. windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
  230. password : crypting password (NULL for no crypting)
  231. crcForCrypting : crc of file to compress (needed for crypting)
  232. */
  233. extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
  234. const char* filename,
  235. const zip_fileinfo* zipfi,
  236. const void* extrafield_local,
  237. uInt size_extrafield_local,
  238. const void* extrafield_global,
  239. uInt size_extrafield_global,
  240. const char* comment,
  241. int method,
  242. int level,
  243. int raw,
  244. int windowBits,
  245. int memLevel,
  246. int strategy,
  247. const char* password,
  248. uLong crcForCrypting,
  249. uLong versionMadeBy,
  250. uLong flagBase
  251. ));
  252. extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
  253. const char* filename,
  254. const zip_fileinfo* zipfi,
  255. const void* extrafield_local,
  256. uInt size_extrafield_local,
  257. const void* extrafield_global,
  258. uInt size_extrafield_global,
  259. const char* comment,
  260. int method,
  261. int level,
  262. int raw,
  263. int windowBits,
  264. int memLevel,
  265. int strategy,
  266. const char* password,
  267. uLong crcForCrypting,
  268. uLong versionMadeBy,
  269. uLong flagBase,
  270. int zip64
  271. ));
  272. /*
  273. Same than zipOpenNewFileInZip4, except
  274. versionMadeBy : value for Version made by field
  275. flag : value for flag field (compression level info will be added)
  276. */
  277. extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
  278. const void* buf,
  279. unsigned len));
  280. /*
  281. Write data in the zipfile
  282. */
  283. extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
  284. /*
  285. Close the current file in the zipfile
  286. */
  287. extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
  288. uLong uncompressed_size,
  289. uLong crc32));
  290. extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
  291. ZPOS64_T uncompressed_size,
  292. uLong crc32));
  293. /*
  294. Close the current file in the zipfile, for file opened with
  295. parameter raw=1 in zipOpenNewFileInZip2
  296. uncompressed_size and crc32 are value for the uncompressed size
  297. */
  298. extern int ZEXPORT zipClose OF((zipFile file,
  299. const char* global_comment));
  300. /*
  301. Close the zipfile
  302. */
  303. extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
  304. /*
  305. zipRemoveExtraInfoBlock - Added by Mathias Svensson
  306. Remove extra information block from a extra information data for the local file header or central directory header
  307. It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
  308. 0x0001 is the signature header for the ZIP64 extra information blocks
  309. usage.
  310. Remove ZIP64 Extra information from a central director extra field data
  311. zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
  312. Remove ZIP64 Extra information from a Local File Header extra field data
  313. zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
  314. */
  315. /*
  316. Added by Sergey A. Tachenov to tweak zipping behaviour.
  317. */
  318. extern int ZEXPORT zipSetFlags(zipFile file, unsigned flags);
  319. extern int ZEXPORT zipClearFlags(zipFile file, unsigned flags);
  320. #ifdef __cplusplus
  321. }
  322. #endif
  323. #endif /* _zip64_H */