Diff
Not logged in

Differences From:

File src/zip.c part of check-in [7a2c37063a] - merge trunk into creole branch by bob on 2009-09-22 07:49:39. Also file src/zip.c part of check-in [5b91887495] - Fix a memory allocation bug in the ZIP archive generator. Ticket 8d6efe4f927 by drh on 2009-08-15 13:21:45. [view]

To:

File src/zip.c part of check-in [d78835d2ff] - Fix the ZIP archive generator so that it works correctly with the OS X Archive Tool. Ticket 923a912309. by drh on 2009-10-18 18:30:56. [view]

@@ -127,10 +127,9 @@
 */
 void zip_add_file(const char *zName, const Blob *pFile){
   z_stream stream;
   int nameLen;
-  int skip;
-  int toOut;
+  int toOut = 0;
   int iStart;
   int iCRC = 0;
   int nByte = 0;
   int nByteCompr = 0;
@@ -178,14 +177,8 @@
   blob_append(&body, zName, nameLen);
   blob_append(&body, zExTime, 13);
 
   if( nBlob>0 ){
-    /* The first two bytes that come out of the deflate compressor are
-    ** some kind of header that ZIP does not use.  So skip the first two
-    ** output bytes.
-    */
-    skip = 2;
-
     /* Write the compressed file.  Compute the CRC as we progress.
     */
     stream.zalloc = (alloc_func)0;
     stream.zfree = (free_func)0;
@@ -193,19 +186,14 @@
     stream.avail_in = blob_size(pFile);
     stream.next_in = (unsigned char*)blob_buffer(pFile);
     stream.avail_out = sizeof(zOutBuf);
     stream.next_out = (unsigned char*)zOutBuf;
-    deflateInit(&stream, 9);
+    deflateInit2(&stream, 9, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY);
     iCRC = crc32(0, stream.next_in, stream.avail_in);
     while( stream.avail_in>0 ){
       deflate(&stream, 0);
       toOut = sizeof(zOutBuf) - stream.avail_out;
-      if( toOut>skip ){
-        blob_append(&body, &zOutBuf[skip], toOut - skip);
-        skip = 0;
-      }else{
-        skip -= toOut;
-      }
+      blob_append(&body, zOutBuf, toOut);
       stream.avail_out = sizeof(zOutBuf);
       stream.next_out = (unsigned char*)zOutBuf;
     }
     do{
@@ -212,17 +200,12 @@
       stream.avail_out = sizeof(zOutBuf);
       stream.next_out = (unsigned char*)zOutBuf;
       deflate(&stream, Z_FINISH);
       toOut = sizeof(zOutBuf) - stream.avail_out;
-      if( toOut>skip ){
-        blob_append(&body, &zOutBuf[skip], toOut - skip);
-        skip = 0;
-      }else{
-        skip -= toOut;
-      }
+      blob_append(&body, zOutBuf, toOut);
     }while( stream.avail_out==0 );
     nByte = stream.total_in;
-    nByteCompr = stream.total_out - 2;
+    nByteCompr = stream.total_out;
     deflateEnd(&stream);
 
     /* Go back and write the header, now that we know the compressed file size.
     */