Fossil SCM

Fix the ZIP archive generator so that it works correctly with the OS X Archive Tool. Ticket [923a912309].

drh 2009-10-18 18:30 trunk
Commit d78835d2ffb6672e214f470af6caeb9cccd9d8c0
1 file changed +5 -22
+5 -22
--- src/zip.c
+++ src/zip.c
@@ -126,12 +126,11 @@
126126
** that the file should be saved as.
127127
*/
128128
void zip_add_file(const char *zName, const Blob *pFile){
129129
z_stream stream;
130130
int nameLen;
131
- int skip;
132
- int toOut;
131
+ int toOut = 0;
133132
int iStart;
134133
int iCRC = 0;
135134
int nByte = 0;
136135
int nByteCompr = 0;
137136
int nBlob; /* Size of the blob */
@@ -177,53 +176,37 @@
177176
blob_append(&body, zHdr, 30);
178177
blob_append(&body, zName, nameLen);
179178
blob_append(&body, zExTime, 13);
180179
181180
if( nBlob>0 ){
182
- /* The first two bytes that come out of the deflate compressor are
183
- ** some kind of header that ZIP does not use. So skip the first two
184
- ** output bytes.
185
- */
186
- skip = 2;
187
-
188181
/* Write the compressed file. Compute the CRC as we progress.
189182
*/
190183
stream.zalloc = (alloc_func)0;
191184
stream.zfree = (free_func)0;
192185
stream.opaque = 0;
193186
stream.avail_in = blob_size(pFile);
194187
stream.next_in = (unsigned char*)blob_buffer(pFile);
195188
stream.avail_out = sizeof(zOutBuf);
196189
stream.next_out = (unsigned char*)zOutBuf;
197
- deflateInit(&stream, 9);
190
+ deflateInit2(&stream, 9, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY);
198191
iCRC = crc32(0, stream.next_in, stream.avail_in);
199192
while( stream.avail_in>0 ){
200193
deflate(&stream, 0);
201194
toOut = sizeof(zOutBuf) - stream.avail_out;
202
- if( toOut>skip ){
203
- blob_append(&body, &zOutBuf[skip], toOut - skip);
204
- skip = 0;
205
- }else{
206
- skip -= toOut;
207
- }
195
+ blob_append(&body, zOutBuf, toOut);
208196
stream.avail_out = sizeof(zOutBuf);
209197
stream.next_out = (unsigned char*)zOutBuf;
210198
}
211199
do{
212200
stream.avail_out = sizeof(zOutBuf);
213201
stream.next_out = (unsigned char*)zOutBuf;
214202
deflate(&stream, Z_FINISH);
215203
toOut = sizeof(zOutBuf) - stream.avail_out;
216
- if( toOut>skip ){
217
- blob_append(&body, &zOutBuf[skip], toOut - skip);
218
- skip = 0;
219
- }else{
220
- skip -= toOut;
221
- }
204
+ blob_append(&body, zOutBuf, toOut);
222205
}while( stream.avail_out==0 );
223206
nByte = stream.total_in;
224
- nByteCompr = stream.total_out - 2;
207
+ nByteCompr = stream.total_out;
225208
deflateEnd(&stream);
226209
227210
/* Go back and write the header, now that we know the compressed file size.
228211
*/
229212
z = &blob_buffer(&body)[iStart];
230213
--- src/zip.c
+++ src/zip.c
@@ -126,12 +126,11 @@
126 ** that the file should be saved as.
127 */
128 void zip_add_file(const char *zName, const Blob *pFile){
129 z_stream stream;
130 int nameLen;
131 int skip;
132 int toOut;
133 int iStart;
134 int iCRC = 0;
135 int nByte = 0;
136 int nByteCompr = 0;
137 int nBlob; /* Size of the blob */
@@ -177,53 +176,37 @@
177 blob_append(&body, zHdr, 30);
178 blob_append(&body, zName, nameLen);
179 blob_append(&body, zExTime, 13);
180
181 if( nBlob>0 ){
182 /* The first two bytes that come out of the deflate compressor are
183 ** some kind of header that ZIP does not use. So skip the first two
184 ** output bytes.
185 */
186 skip = 2;
187
188 /* Write the compressed file. Compute the CRC as we progress.
189 */
190 stream.zalloc = (alloc_func)0;
191 stream.zfree = (free_func)0;
192 stream.opaque = 0;
193 stream.avail_in = blob_size(pFile);
194 stream.next_in = (unsigned char*)blob_buffer(pFile);
195 stream.avail_out = sizeof(zOutBuf);
196 stream.next_out = (unsigned char*)zOutBuf;
197 deflateInit(&stream, 9);
198 iCRC = crc32(0, stream.next_in, stream.avail_in);
199 while( stream.avail_in>0 ){
200 deflate(&stream, 0);
201 toOut = sizeof(zOutBuf) - stream.avail_out;
202 if( toOut>skip ){
203 blob_append(&body, &zOutBuf[skip], toOut - skip);
204 skip = 0;
205 }else{
206 skip -= toOut;
207 }
208 stream.avail_out = sizeof(zOutBuf);
209 stream.next_out = (unsigned char*)zOutBuf;
210 }
211 do{
212 stream.avail_out = sizeof(zOutBuf);
213 stream.next_out = (unsigned char*)zOutBuf;
214 deflate(&stream, Z_FINISH);
215 toOut = sizeof(zOutBuf) - stream.avail_out;
216 if( toOut>skip ){
217 blob_append(&body, &zOutBuf[skip], toOut - skip);
218 skip = 0;
219 }else{
220 skip -= toOut;
221 }
222 }while( stream.avail_out==0 );
223 nByte = stream.total_in;
224 nByteCompr = stream.total_out - 2;
225 deflateEnd(&stream);
226
227 /* Go back and write the header, now that we know the compressed file size.
228 */
229 z = &blob_buffer(&body)[iStart];
230
--- src/zip.c
+++ src/zip.c
@@ -126,12 +126,11 @@
126 ** that the file should be saved as.
127 */
128 void zip_add_file(const char *zName, const Blob *pFile){
129 z_stream stream;
130 int nameLen;
131 int toOut = 0;
 
132 int iStart;
133 int iCRC = 0;
134 int nByte = 0;
135 int nByteCompr = 0;
136 int nBlob; /* Size of the blob */
@@ -177,53 +176,37 @@
176 blob_append(&body, zHdr, 30);
177 blob_append(&body, zName, nameLen);
178 blob_append(&body, zExTime, 13);
179
180 if( nBlob>0 ){
 
 
 
 
 
 
181 /* Write the compressed file. Compute the CRC as we progress.
182 */
183 stream.zalloc = (alloc_func)0;
184 stream.zfree = (free_func)0;
185 stream.opaque = 0;
186 stream.avail_in = blob_size(pFile);
187 stream.next_in = (unsigned char*)blob_buffer(pFile);
188 stream.avail_out = sizeof(zOutBuf);
189 stream.next_out = (unsigned char*)zOutBuf;
190 deflateInit2(&stream, 9, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY);
191 iCRC = crc32(0, stream.next_in, stream.avail_in);
192 while( stream.avail_in>0 ){
193 deflate(&stream, 0);
194 toOut = sizeof(zOutBuf) - stream.avail_out;
195 blob_append(&body, zOutBuf, toOut);
 
 
 
 
 
196 stream.avail_out = sizeof(zOutBuf);
197 stream.next_out = (unsigned char*)zOutBuf;
198 }
199 do{
200 stream.avail_out = sizeof(zOutBuf);
201 stream.next_out = (unsigned char*)zOutBuf;
202 deflate(&stream, Z_FINISH);
203 toOut = sizeof(zOutBuf) - stream.avail_out;
204 blob_append(&body, zOutBuf, toOut);
 
 
 
 
 
205 }while( stream.avail_out==0 );
206 nByte = stream.total_in;
207 nByteCompr = stream.total_out;
208 deflateEnd(&stream);
209
210 /* Go back and write the header, now that we know the compressed file size.
211 */
212 z = &blob_buffer(&body)[iStart];
213

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button