Optimize skipping over Zip entries.

Thanks to: Dan Nelson, who sent me the patch
MFC after: 7 days
This commit is contained in:
Tim Kientzle 2008-02-27 06:05:59 +00:00
parent 6ca61b39bb
commit a26e9253f6

View File

@ -636,7 +636,7 @@ archive_read_format_zip_read_data_skip(struct archive_read *a)
{ {
struct zip *zip; struct zip *zip;
const void *buff = NULL; const void *buff = NULL;
ssize_t bytes_avail; off_t bytes_skipped;
zip = (struct zip *)(a->format->data); zip = (struct zip *)(a->format->data);
@ -659,19 +659,10 @@ archive_read_format_zip_read_data_skip(struct archive_read *a)
* If the length is at the beginning, we can skip the * If the length is at the beginning, we can skip the
* compressed data much more quickly. * compressed data much more quickly.
*/ */
while (zip->entry_bytes_remaining > 0) { bytes_skipped = (a->decompressor->skip)(a, zip->entry_bytes_remaining);
bytes_avail = (a->decompressor->read_ahead)(a, &buff, 1); if (bytes_skipped < 0)
if (bytes_avail <= 0) { return (ARCHIVE_FATAL);
archive_set_error(&a->archive,
ARCHIVE_ERRNO_FILE_FORMAT,
"Truncated ZIP file body");
return (ARCHIVE_FATAL);
}
if (bytes_avail > zip->entry_bytes_remaining)
bytes_avail = zip->entry_bytes_remaining;
(a->decompressor->consume)(a, bytes_avail);
zip->entry_bytes_remaining -= bytes_avail;
}
/* This entry is finished and done. */ /* This entry is finished and done. */
zip->end_of_entry_cleanup = zip->end_of_entry = 1; zip->end_of_entry_cleanup = zip->end_of_entry = 1;
return (ARCHIVE_OK); return (ARCHIVE_OK);