Dump the temporary file generated to emulate stdout at the end of each chunk on decompression and then truncate the file instead of writing the whole file before dumping it.

This commit is contained in:
Con Kolivas 2011-03-07 17:14:07 +11:00
parent 32e182c95a
commit 13a6fb5b43
3 changed files with 16 additions and 7 deletions

17
main.c
View file

@ -186,12 +186,12 @@ static int open_tmpoutfile(void)
}
/* Dump temporary outputfile to perform stdout */
static void dump_tmpoutfile(int fd_out)
void dump_tmpoutfile(int fd_out)
{
FILE *tmpoutfp;
int tmpchar;
print_progress("Dumping to stdout.\n");
print_verbose("Dumping temporary file to stdout.\n");
/* flush anything not yet in the temporary file */
fsync(fd_out);
tmpoutfp = fdopen(fd_out, "r");
@ -199,10 +199,15 @@ static void dump_tmpoutfile(int fd_out)
fatal("Failed to fdopen out tmpfile: %s\n", strerror(errno));
rewind(tmpoutfp);
while ((tmpchar = fgetc(tmpoutfp)) != EOF)
putchar(tmpchar);
if (!TEST_ONLY) {
while ((tmpchar = fgetc(tmpoutfp)) != EOF)
putchar(tmpchar);
}
fflush(stdout);
fflush(control.msgout);
rewind(tmpoutfp);
if (unlikely(ftruncate(fd_out, 0)))
fatal("Failed to ftruncate fd_out in dump_tmpoutfile\n");
}
/* Open a temporary inputfile to perform stdin decompression */
@ -378,7 +383,7 @@ static void decompress_file(void)
runzip_fd(fd_in, fd_out, fd_hist, expected_size);
if (STDOUT && !TEST_ONLY)
if (STDOUT)
dump_tmpoutfile(fd_out);
/* if we get here, no fatal errors during decompression */

View file

@ -242,8 +242,11 @@ i64 runzip_fd(int fd_in, int fd_out, int fd_hist, i64 expected_size)
md5_init_ctx (&control.ctx);
gettimeofday(&start,NULL);
while (total < expected_size)
while (total < expected_size) {
total += runzip_chunk(fd_in, fd_out, fd_hist, expected_size, total);
if (STDOUT)
dump_tmpoutfile(fd_out);
}
gettimeofday(&end,NULL);
print_progress("\nAverage DeCompression Speed: %6.3fMB/s\n",

1
rzip.h
View file

@ -334,6 +334,7 @@ const i64 two_gig;
void prepare_streamout_threads(void);
void close_streamout_threads(void);
void round_to_page(i64 *size);
void dump_tmpoutfile(int fd_out);
#define print_err(format, args...) do {\
fprintf(stderr, format, ##args); \