Line 162... |
Line 162... |
162 |
|
162 |
|
163 |
|
163 |
|
164 |
|
164 |
|
165 |
/* unzips a file. zipfd points to the open zip file, curzipnode to the entry to extract, and fulldestfilename is the destination file where to unzip it. returns 0 on success, non-zero otherwise. */
|
165 |
/* unzips a file. zipfd points to the open zip file, curzipnode to the entry to extract, and fulldestfilename is the destination file where to unzip it. returns 0 on success, non-zero otherwise. */
|
166 |
int zip_unzip(FILE *zipfd, struct ziplist *curzipnode, const char *fulldestfilename) {
|
166 |
int zip_unzip(FILE *zipfd, struct ziplist *curzipnode, const char *fulldestfilename) {
|
167 |
#define buffsize 32 * 1024l /* MUST be at least 32K */
|
167 |
#define buffsize (12 * 1024) /* bigger buffer is better, but pkg has to work on a 256K PC so let's not get too crazy with RAM */
|
168 |
FILE *filefd;
|
168 |
FILE *filefd;
|
169 |
unsigned long cksum;
|
169 |
unsigned long cksum;
|
170 |
int extract_res;
|
170 |
int extract_res;
|
171 |
unsigned char *buff;
|
171 |
unsigned char *buff;
|
172 |
struct utimbuf filetimestamp;
|
172 |
struct utimbuf filetimestamp;
|
Line 213... |
Line 213... |
213 |
crc32_feed(&cksum, buff, toread); /* update the crc32 checksum */
|
213 |
crc32_feed(&cksum, buff, toread); /* update the crc32 checksum */
|
214 |
if (fwrite(buff, toread, 1, filefd) != 1) extract_res = -4; /* write data chunk to dst file */
|
214 |
if (fwrite(buff, toread, 1, filefd) != 1) extract_res = -4; /* write data chunk to dst file */
|
215 |
i += toread;
|
215 |
i += toread;
|
216 |
}
|
216 |
}
|
217 |
} else if (curzipnode->compmethod == 8) { /* if the file is deflated, inflate it */
|
217 |
} else if (curzipnode->compmethod == 8) { /* if the file is deflated, inflate it */
|
- |
|
218 |
/* use 1/3 of my buffer as input and 2/3 as output */
|
218 |
extract_res = inf(zipfd, filefd, buff, &cksum, curzipnode->compressedfilelen);
|
219 |
extract_res = inf(zipfd, filefd, buff, buffsize / 3, buff + (buffsize / 3), buffsize / 3 * 2, &cksum, curzipnode->compressedfilelen);
|
219 |
}
|
220 |
}
|
220 |
|
221 |
|
221 |
/* clean up memory, close the dst file and terminates crc32 */
|
222 |
/* clean up memory, close the dst file and terminates crc32 */
|
222 |
free(buff);
|
223 |
free(buff);
|
223 |
fclose(filefd); /* close the dst file */
|
224 |
fclose(filefd); /* close the dst file */
|
Line 235... |
Line 236... |
235 |
/* Set the timestamp of the new file to what was set in the zip file */
|
236 |
/* Set the timestamp of the new file to what was set in the zip file */
|
236 |
filetimestamp.actime = curzipnode->timestamp;
|
237 |
filetimestamp.actime = curzipnode->timestamp;
|
237 |
filetimestamp.modtime = curzipnode->timestamp;
|
238 |
filetimestamp.modtime = curzipnode->timestamp;
|
238 |
utime(fulldestfilename, &filetimestamp);
|
239 |
utime(fulldestfilename, &filetimestamp);
|
239 |
return(0);
|
240 |
return(0);
|
- |
|
241 |
#undef buffsize
|
240 |
}
|
242 |
}
|
241 |
|
243 |
|
242 |
|
244 |
|
243 |
|
245 |
|
244 |
/* Call this to free a ziplist computed by zip_listfiles() */
|
246 |
/* Call this to free a ziplist computed by zip_listfiles() */
|