From 8756fe91e25545322f66a71974af369157ff9e9d Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 13 Mar 2011 17:52:23 +1100 Subject: [PATCH] Enable decompression when file has been chunked stdout and display progress only when expected size is known. --- lrzip.c | 4 ++-- runzip.c | 22 ++++++++++++---------- stream.c | 1 + 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lrzip.c b/lrzip.c index a4bcc58..5117315 100644 --- a/lrzip.c +++ b/lrzip.c @@ -401,7 +401,7 @@ void decompress_file(rzip_control *control) } if (!STDOUT) - print_progress("Output filename is: %s...Decompressing...\n", control->outfile); + print_progress("Output filename is: %s\n", control->outfile); } if (STDIN) { @@ -465,7 +465,7 @@ void decompress_file(rzip_control *control) print_verbose("CRC32 "); print_verbose("being used for integrity testing.\n"); - print_progress("Decompressing..."); + print_progress("Decompressing...\n"); runzip_fd(control, fd_in, fd_out, fd_hist, expected_size); diff --git a/runzip.c b/runzip.c index d7cb763..06bd559 100644 --- a/runzip.c +++ b/runzip.c @@ -202,9 +202,9 @@ static i64 runzip_chunk(rzip_control *control, int fd_in, int fd_out, int fd_his if (unlikely(read(fd_in, &chunk_bytes, 1) != 1)) fatal("Failed to read chunk_bytes size in runzip_chunk\n"); } - if (!tally) - print_maxverbose("\nExpected size: %lld", expected_size); - print_maxverbose("\nChunk byte width: %d\n", chunk_bytes); + if (!tally && expected_size) + print_maxverbose("Expected size: %lld\n", expected_size); + print_maxverbose("Chunk byte width: %d\n", chunk_bytes); ofs = lseek(fd_in, 0, SEEK_CUR); if (unlikely(ofs == -1)) @@ -227,12 +227,14 @@ static i64 runzip_chunk(rzip_control *control, int fd_in, int fd_out, int fd_his total += unzip_match(control, ss, len, fd_out, fd_hist, &cksum, chunk_bytes); break; } - p = 100 * ((double)(tally + total) / (double)expected_size); - if (p / 10 != l / 10) { - prog_done = (double)(tally + total) / (double)divisor[divisor_index]; - print_progress("%3d%% %9.2f / %9.2f %s\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", - p, prog_done, prog_tsize, suffix[divisor_index] ); - l = p; + if (expected_size) { + p = 100 * ((double)(tally + total) / (double)expected_size); + if (p / 10 != l / 10) { + prog_done = (double)(tally + total) / (double)divisor[divisor_index]; + print_progress("%3d%% %9.2f / %9.2f %s\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", + p, prog_done, prog_tsize, suffix[divisor_index] ); + l = p; + } } } @@ -263,7 +265,7 @@ i64 runzip_fd(rzip_control *control, int fd_in, int fd_out, int fd_hist, i64 exp md5_init_ctx (&control->ctx); gettimeofday(&start,NULL); - while (total < expected_size) { + while (total < expected_size || !control->eof) { total += runzip_chunk(control, fd_in, fd_out, fd_hist, expected_size, total); if (STDOUT) dump_tmpoutfile(control, fd_out); diff --git a/stream.c b/stream.c index 9c68749..ad2ce97 100644 --- a/stream.c +++ b/stream.c @@ -972,6 +972,7 @@ void *open_stream_in(rzip_control *control, int f, int n) print_err("Failed to read in chunk size in open_stream_in\n"); goto failed; } + print_maxverbose("Chunk size: %lld\n", sinfo->size); } sinfo->initial_pos = lseek(f, 0, SEEK_CUR);