Permalink
Browse files

Merge pull request #6 from johnezang/master

commit sez it all, bayybee
  • Loading branch information...
2 parents 53b5c58 + f24f550 commit 65a8282c0b5a6f84bc6266d73bbe7475ef75659d @soffes soffes committed Jul 23, 2011
Showing with 49 additions and 46 deletions.
  1. +7 −6 SSZipArchive.m
  2. +37 −35 minizip/mztools.c
  3. +5 −5 minizip/zip.c
View
@@ -34,7 +34,7 @@ + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination o
return NO;
}
- unz_global_info globalInfo = {0};
+ unz_global_info globalInfo = {0ul, 0ul};
unzGetGlobalInfo(zip, &globalInfo);
// Begin unzipping
@@ -65,8 +65,9 @@ + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination o
}
// Reading data and write to file
- int read;
- unz_file_info fileInfo = {0};
+ unz_file_info fileInfo;
+ memset(&fileInfo, 0, sizeof(unz_file_info));
+
ret = unzGetCurrentFileInfo(zip, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
if (ret != UNZ_OK) {
success = NO;
@@ -107,10 +108,10 @@ + (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination o
FILE *fp = fopen((const char*)[fullPath UTF8String], "wb");
while (fp) {
- read = unzReadCurrentFile(zip, buffer, 4096);
+ int readBytes = unzReadCurrentFile(zip, buffer, 4096);
- if (read > 0) {
- fwrite(buffer, read, 1, fp );
+ if (readBytes > 0) {
+ fwrite(buffer, readBytes, 1, fp );
} else {
break;
}
View
@@ -137,28 +137,28 @@ uLong* bytesRecovered;
/* Central directory entry */
{
- char header[46];
- char* comment = "";
- int comsize = (int) strlen(comment);
- WRITE_32(header, 0x02014b50);
- WRITE_16(header + 4, version);
- WRITE_16(header + 6, version);
- WRITE_16(header + 8, gpflag);
- WRITE_16(header + 10, method);
- WRITE_16(header + 12, filetime);
- WRITE_16(header + 14, filedate);
- WRITE_32(header + 16, crc);
- WRITE_32(header + 20, cpsize);
- WRITE_32(header + 24, uncpsize);
- WRITE_16(header + 28, fnsize);
- WRITE_16(header + 30, extsize);
- WRITE_16(header + 32, comsize);
- WRITE_16(header + 34, 0); /* disk # */
- WRITE_16(header + 36, 0); /* int attrb */
- WRITE_32(header + 38, 0); /* ext attrb */
- WRITE_32(header + 42, currentOffset);
+ char centralDirectoryEntryHeader[46];
+ //char* comment = "";
+ //int comsize = (int) strlen(comment);
+ WRITE_32(centralDirectoryEntryHeader, 0x02014b50);
+ WRITE_16(centralDirectoryEntryHeader + 4, version);
+ WRITE_16(centralDirectoryEntryHeader + 6, version);
+ WRITE_16(centralDirectoryEntryHeader + 8, gpflag);
+ WRITE_16(centralDirectoryEntryHeader + 10, method);
+ WRITE_16(centralDirectoryEntryHeader + 12, filetime);
+ WRITE_16(centralDirectoryEntryHeader + 14, filedate);
+ WRITE_32(centralDirectoryEntryHeader + 16, crc);
+ WRITE_32(centralDirectoryEntryHeader + 20, cpsize);
+ WRITE_32(centralDirectoryEntryHeader + 24, uncpsize);
+ WRITE_16(centralDirectoryEntryHeader + 28, fnsize);
+ WRITE_16(centralDirectoryEntryHeader + 30, extsize);
+ WRITE_16(centralDirectoryEntryHeader + 32, 0 /*comsize*/);
+ WRITE_16(centralDirectoryEntryHeader + 34, 0); /* disk # */
+ WRITE_16(centralDirectoryEntryHeader + 36, 0); /* int attrb */
+ WRITE_32(centralDirectoryEntryHeader + 38, 0); /* ext attrb */
+ WRITE_32(centralDirectoryEntryHeader + 42, currentOffset);
/* Header */
- if (fwrite(header, 1, 46, fpOutCD) == 46) {
+ if (fwrite(centralDirectoryEntryHeader, 1, 46, fpOutCD) == 46) {
offsetCD += 46;
/* Filename */
@@ -185,6 +185,7 @@ uLong* bytesRecovered;
}
/* Comment field */
+ /*
if (comsize > 0) {
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
offsetCD += comsize;
@@ -193,7 +194,7 @@ uLong* bytesRecovered;
break;
}
}
-
+ */
} else {
err = Z_ERRNO;
@@ -212,31 +213,32 @@ uLong* bytesRecovered;
/* Final central directory */
{
int entriesZip = entries;
- char header[22];
- char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
- int comsize = (int) strlen(comment);
+ char finalCentralDirectoryHeader[22];
+ //char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
+ //int comsize = (int) strlen(comment);
if (entriesZip > 0xffff) {
entriesZip = 0xffff;
}
- WRITE_32(header, 0x06054b50);
- WRITE_16(header + 4, 0); /* disk # */
- WRITE_16(header + 6, 0); /* disk # */
- WRITE_16(header + 8, entriesZip); /* hack */
- WRITE_16(header + 10, entriesZip); /* hack */
- WRITE_32(header + 12, offsetCD); /* size of CD */
- WRITE_32(header + 16, offset); /* offset to CD */
- WRITE_16(header + 20, comsize); /* comment */
+ WRITE_32(finalCentralDirectoryHeader, 0x06054b50);
+ WRITE_16(finalCentralDirectoryHeader + 4, 0); /* disk # */
+ WRITE_16(finalCentralDirectoryHeader + 6, 0); /* disk # */
+ WRITE_16(finalCentralDirectoryHeader + 8, entriesZip); /* hack */
+ WRITE_16(finalCentralDirectoryHeader + 10, entriesZip); /* hack */
+ WRITE_32(finalCentralDirectoryHeader + 12, offsetCD); /* size of CD */
+ WRITE_32(finalCentralDirectoryHeader + 16, offset); /* offset to CD */
+ WRITE_16(finalCentralDirectoryHeader + 20, 0 /*comsize*/); /* comment */
/* Header */
- if (fwrite(header, 1, 22, fpOutCD) == 22) {
+ if (fwrite(finalCentralDirectoryHeader, 1, 22, fpOutCD) == 22) {
/* Comment field */
+ /*
if (comsize > 0) {
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
err = Z_ERRNO;
}
}
-
+ */
} else {
err = Z_ERRNO;
}
View
@@ -1070,10 +1070,10 @@ extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
return err;
}
-extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)
+extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32ForFile)
zipFile file;
uLong uncompressed_size;
- uLong crc32;
+ uLong crc32ForFile;
{
zip_internal* zi;
uLong compressed_size;
@@ -1124,15 +1124,15 @@ extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)
if (!zi->ci.raw)
{
- crc32 = (uLong)zi->ci.crc32;
+ crc32ForFile = (uLong)zi->ci.crc32;
uncompressed_size = (uLong)zi->ci.stream.total_in;
}
compressed_size = (uLong)zi->ci.stream.total_out;
# ifndef NOCRYPT
compressed_size += zi->ci.crypt_header_size;
# endif
- ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
+ ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32ForFile,4); /*crc*/
ziplocal_putValue_inmemory(zi->ci.central_header+20,
compressed_size,4); /*compr size*/
if (zi->ci.stream.data_type == Z_ASCII)
@@ -1153,7 +1153,7 @@ extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32)
err = ZIP_ERRNO;
if (err==ZIP_OK)
- err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
+ err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32ForFile,4); /* crc 32, unknown */
if (err==ZIP_OK) /* compressed size, unknown */
err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);

0 comments on commit 65a8282

Please sign in to comment.