38 #include "minizip/zip.h" 58 # define VERSIONMADEBY (0x0) 62 #define Z_BUFSIZE (64*1024) //(16384) 65 #ifndef Z_MAXFILENAMEINZIP 66 #define Z_MAXFILENAMEINZIP (256) 70 # define ALLOC(size) (malloc(size)) 73 # define TRYFREE(p) {if (p) {free(p); }} 85 #define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32)) 100 #if MAX_MEM_LEVEL >= 8 101 # define DEF_MEM_LEVEL 8 103 # define DEF_MEM_LEVEL MAX_MEM_LEVEL 106 const char zip_copyright[] =
" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
109 #define SIZEDATA_INDATABLOCK (4096-(4*4)) 111 #define LOCALHEADERMAGIC (0x04034b50) 112 #define CENTRALHEADERMAGIC (0x02014b50) 113 #define ENDHEADERMAGIC (0x06054b50) 114 #define ZIP64ENDHEADERMAGIC (0x6064b50) 115 #define ZIP64ENDLOCHEADERMAGIC (0x7064b50) 117 #define FLAG_LOCALHEADER_OFFSET (0x06) 118 #define CRC_LOCALHEADER_OFFSET (0x0e) 120 #define SIZECENTRALHEADER (0x2e) 125 uLong avail_in_this_block;
126 uLong filled_in_this_block;
128 unsigned char data[SIZEDATA_INDATABLOCK];
145 int stream_initialised;
146 uInt pos_in_buffered_data;
148 ZPOS64_T pos_local_header;
150 char* central_header;
151 uLong size_centralExtra;
152 uLong size_centralheader;
153 uLong size_centralExtraFree;
158 Byte buffered_data[Z_BUFSIZE];
163 ZPOS64_T pos_zip64extrainfo;
164 ZPOS64_T totalCompressedData;
165 ZPOS64_T totalUncompressedData;
167 unsigned long keys[3];
168 const unsigned long* pcrc_32_tab;
169 int crypt_header_size;
178 int in_opened_file_inzip;
182 ZPOS64_T add_position_when_writting_offset;
183 ZPOS64_T number_entry;
185 #ifndef NO_ADDFILEINEXISTINGZIP 193 #define INCLUDECRYPTINGCODE_IFCRYPTALLOWED 194 #include "minizip/crypt.h" 204 ldi->next_datablock = NULL;
205 ldi->filled_in_this_block = 0;
206 ldi->avail_in_this_block = SIZEDATA_INDATABLOCK;
223 ll->first_block = ll->last_block = NULL;
228 free_datablock(ll->first_block);
229 ll->first_block = ll->last_block = NULL;
233 local
int add_data_in_datablock(
linkedlist_data* ll,
const void* buf, uLong len)
236 const unsigned char* from_copy;
240 return ZIP_INTERNALERROR;
243 if (ll->last_block == NULL)
245 ll->first_block = ll->last_block = allocate_new_datablock();
246 if (ll->first_block == NULL)
248 return ZIP_INTERNALERROR;
252 ldi = ll->last_block;
253 from_copy = (
unsigned char*)buf;
259 unsigned char* to_copy;
261 if (ldi->avail_in_this_block==0)
263 ldi->next_datablock = allocate_new_datablock();
264 if (ldi->next_datablock == NULL)
266 return ZIP_INTERNALERROR;
268 ldi = ldi->next_datablock;
269 ll->last_block = ldi;
272 if (ldi->avail_in_this_block < len)
274 copy_this = (uInt)ldi->avail_in_this_block;
278 copy_this = (uInt)len;
281 to_copy = &(ldi->data[ldi->filled_in_this_block]);
283 for (i = 0; i<copy_this; i++)
285 *(to_copy+i) = *(from_copy+i);
288 ldi->filled_in_this_block += copy_this;
289 ldi->avail_in_this_block -= copy_this;
290 from_copy += copy_this;
300 #ifndef NO_ADDFILEINEXISTINGZIP 306 local
int zip64local_putValue OF((
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T
x,
308 local
int zip64local_putValue (
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T
x,
311 unsigned char buf[8];
313 for (n = 0; n < nbByte; n++)
315 buf[n] = (
unsigned char)(
x & 0xff);
320 for (n = 0; n < nbByte; n++)
326 if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
336 local
void zip64local_putValue_inmemory OF((
void* dest, ZPOS64_T
x,
int nbByte));
337 local
void zip64local_putValue_inmemory (
void* dest, ZPOS64_T
x,
int nbByte)
339 unsigned char* buf = (
unsigned char*)dest;
341 for (n = 0; n < nbByte; n++)
343 buf[n] = (
unsigned char)(
x & 0xff);
349 for (n = 0; n < nbByte; n++)
359 local uLong zip64local_TmzDateToDosDate(
const tm_zip* ptm)
361 uLong year = (uLong)ptm->tm_year;
371 (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
372 ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
378 local
int zip64local_getByte OF((
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream,
int *pi));
383 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
391 if (ZERROR64(*pzlib_filefunc_def,filestream))
406 local
int zip64local_getShort OF((
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
408 local
int zip64local_getShort (
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
414 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
419 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
434 local
int zip64local_getLong OF((
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
436 local
int zip64local_getLong (
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
442 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
447 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
453 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
459 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
474 local
int zip64local_getLong64 OF((
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX));
477 local
int zip64local_getLong64 (
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
483 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
488 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
490 x += ((ZPOS64_T)i)<<8;
494 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
496 x += ((ZPOS64_T)i)<<16;
500 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
502 x += ((ZPOS64_T)i)<<24;
506 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
508 x += ((ZPOS64_T)i)<<32;
512 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
514 x += ((ZPOS64_T)i)<<40;
518 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
520 x += ((ZPOS64_T)i)<<48;
524 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
526 x += ((ZPOS64_T)i)<<56;
540 #ifndef BUFREADCOMMENT 541 #define BUFREADCOMMENT (0x400) 547 local ZPOS64_T zip64local_SearchCentralDir OF((
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
549 local ZPOS64_T zip64local_SearchCentralDir(
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
554 ZPOS64_T uMaxBack = 0xffff;
555 ZPOS64_T uPosFound = 0;
557 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
563 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
565 if (uMaxBack>uSizeFile)
567 uMaxBack = uSizeFile;
570 buf = (
unsigned char*)ALLOC(BUFREADCOMMENT+4);
577 while (uBackRead<uMaxBack)
582 if (uBackRead+BUFREADCOMMENT>uMaxBack)
584 uBackRead = uMaxBack;
588 uBackRead += BUFREADCOMMENT;
590 uReadPos = uSizeFile-uBackRead;
592 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
593 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
594 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
599 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
604 for (i = (
int)uReadSize-3; (i--)>0; )
606 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
607 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
609 uPosFound = uReadPos+i;
627 local ZPOS64_T zip64local_SearchCentralDir64 OF((
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
629 local ZPOS64_T zip64local_SearchCentralDir64(
const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
634 ZPOS64_T uMaxBack = 0xffff;
635 ZPOS64_T uPosFound = 0;
637 ZPOS64_T relativeOffset;
639 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
644 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
646 if (uMaxBack>uSizeFile)
648 uMaxBack = uSizeFile;
651 buf = (
unsigned char*)ALLOC(BUFREADCOMMENT+4);
658 while (uBackRead<uMaxBack)
663 if (uBackRead+BUFREADCOMMENT>uMaxBack)
665 uBackRead = uMaxBack;
669 uBackRead += BUFREADCOMMENT;
671 uReadPos = uSizeFile-uBackRead;
673 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
674 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
675 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
680 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
685 for (i = (
int)uReadSize-3; (i--)>0; )
688 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
690 uPosFound = uReadPos+i;
708 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
714 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
720 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
730 if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK)
736 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
746 if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
752 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
757 if (uL != 0x06064b50)
762 return relativeOffset;
768 ZPOS64_T byte_before_the_zipfile;
770 ZPOS64_T size_central_dir;
771 ZPOS64_T offset_central_dir;
772 ZPOS64_T central_pos;
777 uLong number_disk_with_CD;
779 ZPOS64_T number_entry;
780 ZPOS64_T number_entry_CD;
787 int hasZIP64Record = 0;
790 central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
795 else if(central_pos == 0)
797 central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream);
807 ZPOS64_T sizeEndOfCentralDirectory;
808 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
814 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
820 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK)
826 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK)
832 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK)
838 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
844 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
850 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK)
856 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK)
861 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
863 err = ZIP_BADZIPFILE;
867 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK)
874 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
886 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
892 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
898 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
904 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
911 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
922 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
928 number_entry_CD = uL;
931 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
933 err = ZIP_BADZIPFILE;
937 size_central_dir = 0;
938 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
944 size_central_dir = uL;
948 offset_central_dir = 0;
949 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
955 offset_central_dir = uL;
960 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK)
966 if ((central_pos<offset_central_dir+size_central_dir) &&
969 err = ZIP_BADZIPFILE;
974 ZCLOSE64(pziinit->z_filefunc, pziinit->filestream);
980 pziinit->globalcomment = (
char*)ALLOC(size_comment+1);
981 if (pziinit->globalcomment)
983 size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream,
984 pziinit->globalcomment,size_comment);
985 pziinit->globalcomment[size_comment] = 0;
989 byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
990 pziinit->add_position_when_writting_offset = byte_before_the_zipfile;
993 ZPOS64_T size_central_dir_to_read = size_central_dir;
994 size_t buf_size = SIZEDATA_INDATABLOCK;
995 void* buf_read = (
void*)ALLOC(buf_size);
996 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile,
997 ZLIB_FILEFUNC_SEEK_SET) != 0)
1002 while ((size_central_dir_to_read>0) && (err==ZIP_OK))
1004 ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
1005 if (read_this > size_central_dir_to_read)
1007 read_this = size_central_dir_to_read;
1010 if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this)
1017 err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
1020 size_central_dir_to_read -= read_this;
1024 pziinit->begin_pos = byte_before_the_zipfile;
1025 pziinit->number_entry = number_entry_CD;
1027 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,
1028 ZLIB_FILEFUNC_SEEK_SET) != 0)
1041 extern zipFile MINIZIP_API zipOpen3 (
const void *pathname,
int append, zipcharpc* globalcomment,
1048 ziinit.z_filefunc.zseek32_file = NULL;
1049 ziinit.z_filefunc.ztell32_file = NULL;
1050 if (pzlib_filefunc64_32_def==NULL)
1052 fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
1056 ziinit.z_filefunc = *pzlib_filefunc64_32_def;
1059 ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
1061 (append == APPEND_STATUS_CREATE) ?
1062 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
1063 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
1065 if (ziinit.filestream == NULL)
1070 if (append == APPEND_STATUS_CREATEAFTER)
1072 ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
1075 ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
1076 ziinit.in_opened_file_inzip = 0;
1077 ziinit.ci.stream_initialised = 0;
1078 ziinit.number_entry = 0;
1079 ziinit.add_position_when_writting_offset = 0;
1080 init_linkedlist(&(ziinit.central_dir));
1087 ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
1092 # ifndef NO_ADDFILEINEXISTINGZIP 1093 ziinit.globalcomment = NULL;
1094 if (append == APPEND_STATUS_ADDINZIP)
1097 err = LoadCentralDirectoryRecord(&ziinit);
1102 *globalcomment = ziinit.globalcomment;
1108 # ifndef NO_ADDFILEINEXISTINGZIP 1109 TRYFREE(ziinit.globalcomment);
1121 extern zipFile MINIZIP_API zipOpen2 (
const char *pathname,
int append, zipcharpc* globalcomment,
1124 if (pzlib_filefunc32_def != NULL)
1127 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
1128 return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
1132 return zipOpen3(pathname, append, globalcomment, NULL);
1136 extern zipFile MINIZIP_API zipOpen2_64 (
const void *pathname,
int append, zipcharpc* globalcomment,
1139 if (pzlib_filefunc_def != NULL)
1142 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
1143 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
1144 zlib_filefunc64_32_def_fill.zseek32_file = NULL;
1145 return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
1149 return zipOpen3(pathname, append, globalcomment, NULL);
1155 extern zipFile MINIZIP_API zipOpen (
const char* pathname,
int append)
1157 return zipOpen3((
const void*)pathname,append,NULL,NULL);
1160 extern zipFile MINIZIP_API zipOpen64 (
const void* pathname,
int append)
1162 return zipOpen3(pathname,append,NULL,NULL);
1165 int Write_LocalFileHeader(
zip64_internal* zi,
const char* filename, uInt size_extrafield_local,
1166 const void* extrafield_local)
1170 uInt size_filename = (uInt)strlen(filename);
1171 uInt size_extrafield = size_extrafield_local;
1173 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4);
1179 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
1183 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);
1189 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
1194 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
1199 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
1205 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1211 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4);
1215 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1222 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4);
1226 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
1232 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
1237 size_extrafield += 20;
1242 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2);
1245 if ((err==ZIP_OK) && (size_filename > 0))
1247 if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
1253 if ((err==ZIP_OK) && (size_extrafield_local > 0))
1255 if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local)
1262 if ((err==ZIP_OK) && (zi->ci.zip64))
1266 short DataSize = 16;
1267 ZPOS64_T CompressedSize = 0;
1268 ZPOS64_T UncompressedSize = 0;
1271 zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream);
1273 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (
short)HeaderID,2);
1274 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (
short)DataSize,2);
1276 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8);
1277 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8);
1291 extern MINIZIP_API
int zipOpenNewFileInZip4_64 (zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
1292 const void* extrafield_local, uInt size_extrafield_local,
1293 const void* extrafield_global, uInt size_extrafield_global,
1294 const char* comment,
int method,
int level,
int raw,
1295 int windowBits,
int memLevel,
int strategy,
1296 const char* password, uLong crcForCrypting,
1297 uLong versionMadeBy, uLong flagBase,
int zip64)
1306 if (password != NULL)
1308 return ZIP_PARAMERROR;
1314 return ZIP_PARAMERROR;
1318 if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED))
1320 return ZIP_PARAMERROR;
1323 if ((method!=0) && (method!=Z_DEFLATED))
1325 return ZIP_PARAMERROR;
1331 if (zi->in_opened_file_inzip == 1)
1333 err = zipCloseFileInZip (file);
1351 size_comment = (uInt)strlen(comment);
1354 size_filename = (uInt)strlen(filename);
1362 if (zipfi->dosDate != 0)
1364 zi->ci.dosDate = zipfi->dosDate;
1368 zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date);
1372 zi->ci.flag = flagBase;
1373 if ((level==8) || (level==9))
1385 if (password != NULL)
1391 zi->ci.method = method;
1393 zi->ci.stream_initialised = 0;
1394 zi->ci.pos_in_buffered_data = 0;
1396 zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream);
1398 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment;
1399 zi->ci.size_centralExtraFree = 32;
1401 zi->ci.central_header = (
char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
1403 zi->ci.size_centralExtra = size_extrafield_global;
1404 zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
1406 zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2);
1407 zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
1408 zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
1409 zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
1410 zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
1411 zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4);
1412 zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4);
1413 zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4);
1414 zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
1415 zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
1416 zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
1417 zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2);
1421 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
1425 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
1430 zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
1434 zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
1437 if(zi->ci.pos_local_header >= 0xffffffff)
1439 zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4);
1443 zip64local_putValue_inmemory(zi->ci.central_header+42,
1444 (uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4);
1447 for (i = 0; i<size_filename; i++)
1449 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
1452 for (i = 0; i<size_extrafield_global; i++)
1454 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
1455 *(((
const char*)extrafield_global)+i);
1458 for (i = 0; i<size_comment; i++)
1460 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
1461 size_extrafield_global+i) = *(comment+i);
1463 if (zi->ci.central_header == NULL)
1465 return ZIP_INTERNALERROR;
1468 zi->ci.zip64 = zip64;
1469 zi->ci.totalCompressedData = 0;
1470 zi->ci.totalUncompressedData = 0;
1471 zi->ci.pos_zip64extrainfo = 0;
1473 err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local);
1476 zi->ci.bstream.avail_in = (uInt)0;
1477 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1478 zi->ci.bstream.next_out = (
char*)zi->ci.buffered_data;
1479 zi->ci.bstream.total_in_hi32 = 0;
1480 zi->ci.bstream.total_in_lo32 = 0;
1481 zi->ci.bstream.total_out_hi32 = 0;
1482 zi->ci.bstream.total_out_lo32 = 0;
1485 zi->ci.stream.avail_in = (uInt)0;
1486 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1487 zi->ci.stream.next_out = zi->ci.buffered_data;
1488 zi->ci.stream.total_in = 0;
1489 zi->ci.stream.total_out = 0;
1490 zi->ci.stream.data_type = Z_BINARY;
1493 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1495 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1498 if(zi->ci.method == Z_DEFLATED)
1500 zi->ci.stream.zalloc = (alloc_func)0;
1501 zi->ci.stream.zfree = (free_func)0;
1502 zi->ci.stream.opaque = (voidpf)0;
1506 windowBits = -windowBits;
1509 err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
1513 zi->ci.stream_initialised = Z_DEFLATED;
1516 else if(zi->ci.method == Z_BZIP2ED)
1520 zi->ci.bstream.bzalloc = 0;
1521 zi->ci.bstream.bzfree = 0;
1522 zi->ci.bstream.opaque = (voidpf)0;
1524 err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35);
1527 zi->ci.stream_initialised = Z_BZIP2ED;
1535 zi->ci.crypt_header_size = 0;
1536 if ((err==Z_OK) && (password != NULL))
1538 unsigned char bufHead[RAND_HEAD_LEN];
1539 unsigned int sizeHead;
1541 zi->ci.pcrc_32_tab = get_crc_table();
1544 sizeHead = crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,
1546 zi->ci.crypt_header_size = sizeHead;
1548 if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
1557 zi->in_opened_file_inzip = 1;
1562 extern MINIZIP_API
int zipOpenNewFileInZip4 (zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
1563 const void* extrafield_local, uInt size_extrafield_local,
1564 const void* extrafield_global, uInt size_extrafield_global,
1565 const char* comment,
int method,
int level,
int raw,
1566 int windowBits,
int memLevel,
int strategy,
1567 const char* password, uLong crcForCrypting,
1568 uLong versionMadeBy, uLong flagBase)
1570 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1571 extrafield_local, size_extrafield_local,
1572 extrafield_global, size_extrafield_global,
1573 comment, method, level, raw,
1574 windowBits, memLevel, strategy,
1575 password, crcForCrypting, versionMadeBy, flagBase, 0);
1578 extern MINIZIP_API
int zipOpenNewFileInZip3 (zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
1579 const void* extrafield_local, uInt size_extrafield_local,
1580 const void* extrafield_global, uInt size_extrafield_global,
1581 const char* comment,
int method,
int level,
int raw,
1582 int windowBits,
int memLevel,
int strategy,
1583 const char* password, uLong crcForCrypting)
1585 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1586 extrafield_local, size_extrafield_local,
1587 extrafield_global, size_extrafield_global,
1588 comment, method, level, raw,
1589 windowBits, memLevel, strategy,
1590 password, crcForCrypting, VERSIONMADEBY, 0, 0);
1593 extern MINIZIP_API
int zipOpenNewFileInZip3_64(zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
1594 const void* extrafield_local, uInt size_extrafield_local,
1595 const void* extrafield_global, uInt size_extrafield_global,
1596 const char* comment,
int method,
int level,
int raw,
1597 int windowBits,
int memLevel,
int strategy,
1598 const char* password, uLong crcForCrypting,
int zip64)
1600 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1601 extrafield_local, size_extrafield_local,
1602 extrafield_global, size_extrafield_global,
1603 comment, method, level, raw,
1604 windowBits, memLevel, strategy,
1605 password, crcForCrypting, VERSIONMADEBY, 0, zip64);
1608 extern MINIZIP_API
int zipOpenNewFileInZip2(zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
1609 const void* extrafield_local, uInt size_extrafield_local,
1610 const void* extrafield_global, uInt size_extrafield_global,
1611 const char* comment,
int method,
int level,
int raw)
1613 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1614 extrafield_local, size_extrafield_local,
1615 extrafield_global, size_extrafield_global,
1616 comment, method, level, raw,
1617 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1618 NULL, 0, VERSIONMADEBY, 0, 0);
1621 extern MINIZIP_API
int zipOpenNewFileInZip2_64(zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
1622 const void* extrafield_local, uInt size_extrafield_local,
1623 const void* extrafield_global, uInt size_extrafield_global,
1624 const char* comment,
int method,
int level,
int raw,
int zip64)
1626 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1627 extrafield_local, size_extrafield_local,
1628 extrafield_global, size_extrafield_global,
1629 comment, method, level, raw,
1630 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1631 NULL, 0, VERSIONMADEBY, 0, zip64);
1634 extern MINIZIP_API
int zipOpenNewFileInZip64 (zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
1635 const void* extrafield_local, uInt size_extrafield_local,
1636 const void*extrafield_global, uInt size_extrafield_global,
1637 const char* comment,
int method,
int level,
int zip64)
1639 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1640 extrafield_local, size_extrafield_local,
1641 extrafield_global, size_extrafield_global,
1642 comment, method, level, 0,
1643 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1644 NULL, 0, VERSIONMADEBY, 0, zip64);
1647 extern MINIZIP_API
int zipOpenNewFileInZip (zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
1648 const void* extrafield_local, uInt size_extrafield_local,
1649 const void*extrafield_global, uInt size_extrafield_global,
1650 const char* comment,
int method,
int level)
1652 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
1653 extrafield_local, size_extrafield_local,
1654 extrafield_global, size_extrafield_global,
1655 comment, method, level, 0,
1656 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
1657 NULL, 0, VERSIONMADEBY, 0, 0);
1664 if (zi->ci.encrypt != 0)
1669 for (i = 0; i<zi->ci.pos_in_buffered_data; i++)
1671 zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t);
1676 if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,
1677 zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data)
1682 zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data;
1685 if(zi->ci.method == Z_BZIP2ED)
1687 zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32;
1688 zi->ci.bstream.total_in_lo32 = 0;
1689 zi->ci.bstream.total_in_hi32 = 0;
1694 zi->ci.totalUncompressedData += zi->ci.stream.total_in;
1695 zi->ci.stream.total_in = 0;
1699 zi->ci.pos_in_buffered_data = 0;
1704 extern MINIZIP_API
int zipWriteInFileInZip (zipFile file,
const void* buf,
unsigned int len)
1711 return ZIP_PARAMERROR;
1715 if (zi->in_opened_file_inzip == 0)
1717 return ZIP_PARAMERROR;
1720 zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len);
1723 if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw))
1725 zi->ci.bstream.next_in = (
void*)buf;
1726 zi->ci.bstream.avail_in = len;
1729 while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0))
1731 if (zi->ci.bstream.avail_out == 0)
1733 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1737 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1738 zi->ci.bstream.next_out = (
char*)zi->ci.buffered_data;
1742 if(err != BZ_RUN_OK)
1747 if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1749 uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
1751 err = BZ2_bzCompress(&zi->ci.bstream, BZ_RUN);
1753 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo);
1757 if(err == BZ_RUN_OK)
1765 zi->ci.stream.next_in = (Bytef*)buf;
1766 zi->ci.stream.avail_in = len;
1768 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
1770 if (zi->ci.stream.avail_out == 0)
1772 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1776 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1777 zi->ci.stream.next_out = zi->ci.buffered_data;
1786 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1788 uLong uTotalOutBefore = zi->ci.stream.total_out;
1789 err = deflate(&zi->ci.stream, Z_NO_FLUSH);
1790 if(uTotalOutBefore > zi->ci.stream.total_out)
1796 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore);
1801 if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
1803 copy_this = zi->ci.stream.avail_in;
1807 copy_this = zi->ci.stream.avail_out;
1810 for (i = 0; i < copy_this; i++)
1812 *(((
char*)zi->ci.stream.next_out)+i) =
1813 *(((
const char*)zi->ci.stream.next_in)+i);
1816 zi->ci.stream.avail_in -= copy_this;
1817 zi->ci.stream.avail_out -= copy_this;
1818 zi->ci.stream.next_in += copy_this;
1819 zi->ci.stream.next_out += copy_this;
1820 zi->ci.stream.total_in += copy_this;
1821 zi->ci.stream.total_out += copy_this;
1822 zi->ci.pos_in_buffered_data += copy_this;
1831 extern MINIZIP_API
int zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32)
1833 return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
1836 extern MINIZIP_API
int zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
1839 ZPOS64_T compressed_size;
1840 uLong invalidValue = 0xffffffff;
1846 return ZIP_PARAMERROR;
1850 if (zi->in_opened_file_inzip == 0)
1852 return ZIP_PARAMERROR;
1854 zi->ci.stream.avail_in = 0;
1856 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1860 uLong uTotalOutBefore;
1861 if (zi->ci.stream.avail_out == 0)
1863 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1867 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1868 zi->ci.stream.next_out = zi->ci.buffered_data;
1870 uTotalOutBefore = zi->ci.stream.total_out;
1871 err = deflate(&zi->ci.stream, Z_FINISH);
1872 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore);
1875 else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1879 while (err==BZ_FINISH_OK)
1881 uLong uTotalOutBefore;
1882 if (zi->ci.bstream.avail_out == 0)
1884 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1888 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1889 zi->ci.bstream.next_out = (
char*)zi->ci.buffered_data;
1891 uTotalOutBefore = zi->ci.bstream.total_out_lo32;
1892 err = BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH);
1893 if(err == BZ_STREAM_END)
1898 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore);
1901 if(err == BZ_FINISH_OK)
1908 if (err==Z_STREAM_END)
1913 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
1915 if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO)
1921 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
1923 int tmp_err = deflateEnd(&zi->ci.stream);
1928 zi->ci.stream_initialised = 0;
1931 else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
1933 int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
1938 zi->ci.stream_initialised = 0;
1944 crc32 = (uLong)zi->ci.crc32;
1945 uncompressed_size = zi->ci.totalUncompressedData;
1947 compressed_size = zi->ci.totalCompressedData;
1950 compressed_size += zi->ci.crypt_header_size;
1954 if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
1957 zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2);
1959 zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2);
1963 zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4);
1966 if(compressed_size >= 0xffffffff)
1968 zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4);
1972 zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4);
1976 if (zi->ci.stream.data_type == Z_ASCII)
1978 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
1981 if(uncompressed_size >= 0xffffffff)
1983 zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4);
1987 zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4);
1991 if(uncompressed_size >= 0xffffffff)
1997 if(compressed_size >= 0xffffffff)
2003 if(zi->ci.pos_local_header >= 0xffffffff)
2012 if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
2015 return ZIP_BADZIPFILE;
2018 p = zi->ci.central_header + zi->ci.size_centralheader;
2021 zip64local_putValue_inmemory(p, 0x0001, 2);
2023 zip64local_putValue_inmemory(p, datasize, 2);
2026 if(uncompressed_size >= 0xffffffff)
2028 zip64local_putValue_inmemory(p, uncompressed_size, 8);
2032 if(compressed_size >= 0xffffffff)
2034 zip64local_putValue_inmemory(p, compressed_size, 8);
2038 if(zi->ci.pos_local_header >= 0xffffffff)
2040 zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8);
2047 zi->ci.size_centralExtraFree -= datasize + 4;
2048 zi->ci.size_centralheader += datasize + 4;
2051 zi->ci.size_centralExtra += datasize + 4;
2052 zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2);
2057 err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
2060 free(zi->ci.central_header);
2066 ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
2068 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
2075 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4);
2078 if(uncompressed_size >= 0xffffffff)
2080 if(zi->ci.pos_zip64extrainfo > 0)
2083 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0)
2090 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);
2095 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
2103 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
2108 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
2112 if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
2119 zi->in_opened_file_inzip = 0;
2124 extern MINIZIP_API
int zipCloseFileInZip (zipFile file)
2126 return zipCloseFileInZipRaw (file,0,0);
2129 int Write_Zip64EndOfCentralDirectoryLocator(
zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip)
2132 ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset;
2134 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4);
2139 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
2145 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8);
2151 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4);
2157 int Write_Zip64EndOfCentralDirectoryRecord(
zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
2161 uLong Zip64DataSize = 44;
2163 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
2167 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8);
2172 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
2177 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
2182 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
2187 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
2192 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
2197 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
2202 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8);
2207 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
2208 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
2212 int Write_EndOfCentralDirectoryRecord(
zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
2217 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
2221 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
2226 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
2232 if(zi->number_entry >= 0xFFFF)
2234 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2);
2238 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
2245 if(zi->number_entry >= 0xFFFF)
2247 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2);
2251 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
2257 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
2262 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
2263 if(pos >= 0xffffffff)
2265 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4);
2270 zip64local_putValue(&zi->z_filefunc,zi->filestream,
2271 (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
2278 int Write_GlobalComment(
zip64_internal* zi,
const char* global_comment)
2281 uInt size_global_comment = 0;
2283 if(global_comment != NULL)
2285 size_global_comment = (uInt)strlen(global_comment);
2288 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
2290 if (err == ZIP_OK && size_global_comment > 0)
2292 if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment)
2300 extern MINIZIP_API
int zipClose (zipFile file,
const char* global_comment)
2304 uLong size_centraldir = 0;
2305 ZPOS64_T centraldir_pos_inzip;
2310 return ZIP_PARAMERROR;
2315 if (zi->in_opened_file_inzip == 1)
2317 err = zipCloseFileInZip (file);
2320 #ifndef NO_ADDFILEINEXISTINGZIP 2321 if (global_comment==NULL)
2323 global_comment = zi->globalcomment;
2327 centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
2334 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
2336 if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data,
2337 ldi->filled_in_this_block) != ldi->filled_in_this_block)
2343 size_centraldir += ldi->filled_in_this_block;
2344 ldi = ldi->next_datablock;
2347 free_linkedlist(&(zi->central_dir));
2349 pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
2350 if(pos >= 0xffffffff)
2352 ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream);
2353 Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
2355 Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos);
2360 err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
2365 err = Write_GlobalComment(zi, global_comment);
2368 if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0)
2376 #ifndef NO_ADDFILEINEXISTINGZIP 2377 TRYFREE(zi->globalcomment);
2384 extern MINIZIP_API
int zipRemoveExtraInfoBlock (
char* pData,
int* dataLen,
short sHeader)
2393 int retVal = ZIP_OK;
2395 if(pData == NULL || *dataLen < 4)
2397 return ZIP_PARAMERROR;
2400 pNewHeader = (
char*)ALLOC(*dataLen);
2403 while(p < (pData + *dataLen))
2405 header = *(
short*)p;
2406 dataSize = *(((
short*)p)+1);
2408 if( header == sHeader )
2415 memcpy(pTmp, p, dataSize + 4);
2417 size += dataSize + 4;
2425 memset(pData,0, *dataLen);
2430 memcpy(pData, pNewHeader, size);
2443 TRYFREE(pNewHeader);