From 2551ce7c180b8f54bb64779244b453c85871aaf6 Mon Sep 17 00:00:00 2001 From: Frederic Langlet Date: Fri, 10 Nov 2023 13:42:01 +0100 Subject: [PATCH] Treat empty files as regular files --- v2/app/BlockCompressor.go | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/v2/app/BlockCompressor.go b/v2/app/BlockCompressor.go index f22618a0..3c8154f1 100644 --- a/v2/app/BlockCompressor.go +++ b/v2/app/BlockCompressor.go @@ -824,14 +824,6 @@ func (this *fileCompressTask) call() (int, uint64, uint64) { length, err = input.Read(buffer) } - if read == 0 { - msg = fmt.Sprintf("Input file %s is empty ... nothing to do", inputName) - log.Println(msg, verbosity > 0) - output.Close() - os.Remove(outputName) // best effort to delete output file, ignore return code - return 0, read, cos.GetWritten() - } - // Close streams to ensure all data are flushed // Deferred close is fallback for error paths if err := cos.Close(); err != nil { @@ -851,8 +843,6 @@ func (this *fileCompressTask) call() (int, uint64, uint64) { msg = fmt.Sprintf("%.0f ms", float64(delta)) } - f := float64(cos.GetWritten()) / float64(read) - if verbosity > 1 { msg = fmt.Sprintf("Compressing: %s", msg) log.Println(msg, true) @@ -860,16 +850,23 @@ func (this *fileCompressTask) call() (int, uint64, uint64) { log.Println(msg, true) msg = fmt.Sprintf("Output size: %d", cos.GetWritten()) log.Println(msg, true) - msg = fmt.Sprintf("Compression ratio: %f", f) - log.Println(msg, true) - } - if verbosity == 1 { - msg = fmt.Sprintf("Compressing %s: %d => %d (%.2f%%) in %s", inputName, read, cos.GetWritten(), 100*f, msg) + if read != 0 { + msg = fmt.Sprintf("Compression ratio: %f", float64(cos.GetWritten())/float64(read)) + log.Println(msg, true) + } + } else if verbosity == 1 { + if read == 0 { + msg = fmt.Sprintf("Compressing %s: %d => %d in %s", inputName, read, cos.GetWritten(), msg) + } else { + f := float64(cos.GetWritten()) / float64(read) + msg = fmt.Sprintf("Compressing %s: %d => %d (%.2f%%) in %s", inputName, read, cos.GetWritten(), 100*f, msg) + } + log.Println(msg, true) } - if verbosity > 1 && delta > 0 { + if verbosity > 1 && delta != 0 && read != 0 { msg = fmt.Sprintf("Throughput (KB/s): %d", ((int64(read*1000))>>10)/delta) log.Println(msg, true) }