Check-in [d78835d2ff]
Not logged in
Overview

SHA1 Hash:d78835d2ffb6672e214f470af6caeb9cccd9d8c0
Date: 2009-10-18 18:30:56
User: drh
Comment:Fix the ZIP archive generator so that it works correctly with the OS X Archive Tool. Ticket 923a912309.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/zip.c from [8c1776ca5d] to [43608365d5].

@@ -126,12 +126,11 @@
 ** that the file should be saved as.
 */
 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;
   int nBlob;                 /* Size of the blob */
@@ -177,53 +176,37 @@
   blob_append(&body, zHdr, 30);
   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;
     stream.opaque = 0;
     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{
       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.
     */
     z = &blob_buffer(&body)[iStart];