zip.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. #ifndef _zip12_H
  28. #define _zip12_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. //#define HAVE_BZIP2
  33. #ifndef _ZLIB_H
  34. #include "zlib.h"
  35. #endif
  36. #ifndef _ZLIBIOAPI_H
  37. #include "ioapi.h"
  38. #endif
  39. #ifdef HAVE_BZIP2
  40. #include "bzlib.h"
  41. #endif
  42. #define Z_BZIP2ED 12
  43. #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
  44. /* like the STRICT of WIN32, we define a pointer that cannot be converted
  45. from (void*) without cast */
  46. typedef struct TagzipFile__ { int unused; } zipFile__;
  47. typedef zipFile__ *zipFile;
  48. #else
  49. typedef voidp zipFile;
  50. #endif
  51. #define ZIP_OK (0)
  52. #define ZIP_EOF (0)
  53. #define ZIP_ERRNO (Z_ERRNO)
  54. #define ZIP_PARAMERROR (-102)
  55. #define ZIP_BADZIPFILE (-103)
  56. #define ZIP_INTERNALERROR (-104)
  57. #ifndef DEF_MEM_LEVEL
  58. # if MAX_MEM_LEVEL >= 8
  59. # define DEF_MEM_LEVEL 8
  60. # else
  61. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  62. # endif
  63. #endif
  64. /* default memLevel */
  65. /* tm_zip contain date/time info */
  66. typedef struct tm_zip_s
  67. {
  68. int tm_sec; /* seconds after the minute - [0,59] */
  69. int tm_min; /* minutes after the hour - [0,59] */
  70. int tm_hour; /* hours since midnight - [0,23] */
  71. int tm_mday; /* day of the month - [1,31] */
  72. int tm_mon; /* months since January - [0,11] */
  73. int tm_year; /* years - [1980..2044] */
  74. } tm_zip;
  75. typedef struct
  76. {
  77. tm_zip tmz_date; /* date in understandable format */
  78. uLong dosDate; /* if dos_date == 0, tmu_date is used */
  79. /* uLong flag; */ /* general purpose bit flag 2 bytes */
  80. uLong internal_fa; /* internal file attributes 2 bytes */
  81. uLong external_fa; /* external file attributes 4 bytes */
  82. } zip_fileinfo;
  83. typedef const char* zipcharpc;
  84. #define APPEND_STATUS_CREATE (0)
  85. #define APPEND_STATUS_CREATEAFTER (1)
  86. #define APPEND_STATUS_ADDINZIP (2)
  87. extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
  88. extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
  89. /*
  90. Create a zipfile.
  91. pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
  92. an Unix computer "zlib/zlib113.zip".
  93. if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
  94. will be created at the end of the file.
  95. (useful if the file contain a self extractor code)
  96. if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
  97. add files in existing zip (be sure you don't add file that doesn't exist)
  98. If the zipfile cannot be opened, the return value is NULL.
  99. Else, the return value is a zipFile Handle, usable with other function
  100. of this zip package.
  101. */
  102. /* Note : there is no delete function into a zipfile.
  103. If you want delete file into a zipfile, you must open a zipfile, and create another
  104. Of couse, you can use RAW reading and writing to copy the file you did not want delte
  105. */
  106. extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
  107. int append,
  108. zipcharpc* globalcomment,
  109. zlib_filefunc_def* pzlib_filefunc_def));
  110. extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
  111. int append,
  112. zipcharpc* globalcomment,
  113. zlib_filefunc64_def* pzlib_filefunc_def));
  114. extern zipFile ZEXPORT zipOpen3 OF((const void *pathname,
  115. int append,
  116. zipcharpc* globalcomment,
  117. zlib_filefunc64_32_def* pzlib_filefunc64_32_def));
  118. extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
  119. const char* filename,
  120. const zip_fileinfo* zipfi,
  121. const void* extrafield_local,
  122. uInt size_extrafield_local,
  123. const void* extrafield_global,
  124. uInt size_extrafield_global,
  125. const char* comment,
  126. int method,
  127. int level));
  128. extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
  129. const char* filename,
  130. const zip_fileinfo* zipfi,
  131. const void* extrafield_local,
  132. uInt size_extrafield_local,
  133. const void* extrafield_global,
  134. uInt size_extrafield_global,
  135. const char* comment,
  136. int method,
  137. int level,
  138. int zip64));
  139. /*
  140. Open a file in the ZIP for writing.
  141. filename : the filename in zip (if NULL, '-' without quote will be used
  142. *zipfi contain supplemental information
  143. if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
  144. contains the extrafield data the the local header
  145. if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
  146. contains the extrafield data the the local header
  147. if comment != NULL, comment contain the comment string
  148. method contain the compression method (0 for store, Z_DEFLATED for deflate)
  149. level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
  150. zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
  151. this MUST be '1' if the uncompressed size is >= 0xffffffff.
  152. */
  153. extern int ZEXPORT 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. extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
  165. const char* filename,
  166. const zip_fileinfo* zipfi,
  167. const void* extrafield_local,
  168. uInt size_extrafield_local,
  169. const void* extrafield_global,
  170. uInt size_extrafield_global,
  171. const char* comment,
  172. int method,
  173. int level,
  174. int raw,
  175. int zip64));
  176. /*
  177. Same than zipOpenNewFileInZip, except if raw=1, we write raw file
  178. */
  179. extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
  180. const char* filename,
  181. const zip_fileinfo* zipfi,
  182. const void* extrafield_local,
  183. uInt size_extrafield_local,
  184. const void* extrafield_global,
  185. uInt size_extrafield_global,
  186. const char* comment,
  187. int method,
  188. int level,
  189. int raw,
  190. int windowBits,
  191. int memLevel,
  192. int strategy,
  193. const char* password,
  194. uLong crcForCrypting));
  195. extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
  196. const char* filename,
  197. const zip_fileinfo* zipfi,
  198. const void* extrafield_local,
  199. uInt size_extrafield_local,
  200. const void* extrafield_global,
  201. uInt size_extrafield_global,
  202. const char* comment,
  203. int method,
  204. int level,
  205. int raw,
  206. int windowBits,
  207. int memLevel,
  208. int strategy,
  209. const char* password,
  210. uLong crcForCrypting,
  211. int zip64
  212. ));
  213. /*
  214. Same than zipOpenNewFileInZip2, except
  215. windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
  216. password : crypting password (NULL for no crypting)
  217. crcForCrypting : crc of file to compress (needed for crypting)
  218. */
  219. extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
  220. const char* filename,
  221. const zip_fileinfo* zipfi,
  222. const void* extrafield_local,
  223. uInt size_extrafield_local,
  224. const void* extrafield_global,
  225. uInt size_extrafield_global,
  226. const char* comment,
  227. int method,
  228. int level,
  229. int raw,
  230. int windowBits,
  231. int memLevel,
  232. int strategy,
  233. const char* password,
  234. uLong crcForCrypting,
  235. uLong versionMadeBy,
  236. uLong flagBase
  237. ));
  238. extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
  239. const char* filename,
  240. const zip_fileinfo* zipfi,
  241. const void* extrafield_local,
  242. uInt size_extrafield_local,
  243. const void* extrafield_global,
  244. uInt size_extrafield_global,
  245. const char* comment,
  246. int method,
  247. int level,
  248. int raw,
  249. int windowBits,
  250. int memLevel,
  251. int strategy,
  252. const char* password,
  253. uLong crcForCrypting,
  254. uLong versionMadeBy,
  255. uLong flagBase,
  256. int zip64
  257. ));
  258. /*
  259. Same than zipOpenNewFileInZip4, except
  260. versionMadeBy : value for Version made by field
  261. flag : value for flag field (compression level info will be added)
  262. */
  263. extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
  264. const void* buf,
  265. unsigned len));
  266. /*
  267. Write data in the zipfile
  268. */
  269. extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
  270. /*
  271. Close the current file in the zipfile
  272. */
  273. extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
  274. uLong uncompressed_size,
  275. uLong crc32));
  276. extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
  277. ZPOS64_T uncompressed_size,
  278. uLong crc32));
  279. /*
  280. Close the current file in the zipfile, for file opened with
  281. parameter raw=1 in zipOpenNewFileInZip2
  282. uncompressed_size and crc32 are value for the uncompressed size
  283. */
  284. extern int ZEXPORT zipClose OF((zipFile file,
  285. const char* global_comment));
  286. /*
  287. Close the zipfile
  288. */
  289. extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
  290. /*
  291. zipRemoveExtraInfoBlock - Added by Mathias Svensson
  292. Remove extra information block from a extra information data for the local file header or central directory header
  293. It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
  294. 0x0001 is the signature header for the ZIP64 extra information blocks
  295. usage.
  296. Remove ZIP64 Extra information from a central director extra field data
  297. zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
  298. Remove ZIP64 Extra information from a Local File Header extra field data
  299. zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
  300. */
  301. #ifdef __cplusplus
  302. }
  303. #endif
  304. #endif /* _zip64_H */