From e02590e4724e01beef82939eca6480fc7ebc2e8d Mon Sep 17 00:00:00 2001 From: bug1 Date: Fri, 14 Nov 2003 08:26:25 +0000 Subject: Read in blocks rather than one char at a time, greatly improves speed git-svn-id: svn://busybox.net/trunk/busybox@7907 69ca8d6d-28ef-0310-b511-8ec308f3f277 --- archival/libunarchive/seek_by_char.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/archival/libunarchive/seek_by_char.c b/archival/libunarchive/seek_by_char.c index f33935cb5..77da4ef2e 100644 --- a/archival/libunarchive/seek_by_char.c +++ b/archival/libunarchive/seek_by_char.c @@ -14,12 +14,31 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include + #include "unarchive.h" +#include "busybox.h" -extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int amount) +/* If we are reading through a pipe(), or from stdin then we cant lseek, + * we must read and discard the data to skip over it. + * + * TODO: rename to seek_by_read + */ +extern void seek_by_char(const archive_handle_t *archive_handle, const unsigned int jump_size) { - unsigned int i; - for (i = 0; i < amount; i++) { - archive_xread_char(archive_handle); + unsigned int remaining = jump_size; + unsigned int read_amount; + RESERVE_CONFIG_BUFFER(buf, BUFSIZ); + + while (remaining > 0) { + if (remaining > BUFSIZ) { + read_amount = BUFSIZ; + } else { + read_amount = remaining; + } + read_amount = archive_xread(archive_handle, buf, read_amount); + remaining -= read_amount; } + + RELEASE_CONFIG_BUFFER(buf); } -- cgit v1.2.3-55-g6feb