Fossil

Check-in [d78835d2]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the ZIP archive generator so that it works correctly with the OS X Archive Tool. Ticket [923a912309].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d78835d2ffb6672e214f470af6caeb9cccd9d8c0
User & Date: drh 2009-10-18 18:30:56
References
2009-10-25
13:47 New ticket [36d5fbf9] Revert's error handling is suboptimal.. artifact: d2bc610b user: anonymous
2009-10-20
23:34 New ticket [574d53a2] Column headers doesn't match columns value in raw view report. artifact: 273f40ae user: anonymous
Context
2009-10-21
15:43
update makefile for win32 check-in: 3275d9c6 user: rwilson tags: trunk
2009-10-18
18:30
Fix the ZIP archive generator so that it works correctly with the OS X Archive Tool. Ticket [923a912309]. check-in: d78835d2 user: drh tags: trunk
18:21
Begin adding a search capability; the code is not yet connected up. Also update to the latest version of SQLite. check-in: 232d10b7 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/zip.c.

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
**
** pFile is the file to be appended.  zName is the name
** 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 iStart;
  int iCRC = 0;
  int nByte = 0;
  int nByteCompr = 0;
  int nBlob;                 /* Size of the blob */
  int iMethod;               /* Compression method. */
  int iMode = 0644;          /* Access permissions */
................................................................................
  */
  iStart = blob_size(&body);
  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);
    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;
      }
      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;
      }
    }while( stream.avail_out==0 );
    nByte = stream.total_in;
    nByteCompr = stream.total_out - 2;
    deflateEnd(&stream);
  
    /* Go back and write the header, now that we know the compressed file size.
    */
    z = &blob_buffer(&body)[iStart];
    put32(&z[14], iCRC);
    put32(&z[18], nByteCompr);







<
|







 







<
<
<
<
<
<









|




<
|
<
<
<
<








<
|
<
<
<
<


|







124
125
126
127
128
129
130

131
132
133
134
135
136
137
138
...
174
175
176
177
178
179
180






181
182
183
184
185
186
187
188
189
190
191
192
193
194

195




196
197
198
199
200
201
202
203

204




205
206
207
208
209
210
211
212
213
214
**
** pFile is the file to be appended.  zName is the name
** that the file should be saved as.
*/
void zip_add_file(const char *zName, const Blob *pFile){
  z_stream stream;
  int nameLen;

  int toOut = 0;
  int iStart;
  int iCRC = 0;
  int nByte = 0;
  int nByteCompr = 0;
  int nBlob;                 /* Size of the blob */
  int iMethod;               /* Compression method. */
  int iMode = 0644;          /* Access permissions */
................................................................................
  */
  iStart = blob_size(&body);
  blob_append(&body, zHdr, 30);
  blob_append(&body, zName, nameLen);
  blob_append(&body, zExTime, 13);

  if( nBlob>0 ){






    /* 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;
    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;

      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;

      blob_append(&body, zOutBuf, toOut);




    }while( stream.avail_out==0 );
    nByte = stream.total_in;
    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];
    put32(&z[14], iCRC);
    put32(&z[18], nByteCompr);