mirror of
https://github.com/ckolivas/lrzip.git
synced 2025-12-06 07:12:00 +01:00
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:
parent
32e182c95a
commit
13a6fb5b43
13
main.c
13
main.c
|
|
@ -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);
|
||||
|
||||
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 */
|
||||
|
|
|
|||
5
runzip.c
5
runzip.c
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue