Skip to content

Commit

Permalink
Treat empty files as regular files
Browse files Browse the repository at this point in the history
  • Loading branch information
flanglet committed Nov 10, 2023
1 parent c723d28 commit 2551ce7
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions v2/app/BlockCompressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -851,25 +843,30 @@ 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)
msg = fmt.Sprintf("Input size: %d", read)
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)
}
Expand Down

0 comments on commit 2551ce7

Please sign in to comment.