export total_compressed_size=0
export total_files_scanned=0
export total_empty_files=0
+export total_uncompressed_size_estimated=0
+export total_compressed_size_estimated=0
round_to_block_size() {
local size=$1
# Round up the file_size to the next block (actual space usage)
file_size=$(round_to_block_size file_size)
-
# Accumulate the total size of files scanned (in block_size units)
total_file_size=$((total_file_size + file_size))
done
+ # Get current ratio for this file
+ current_ratio=$((sum_uncompressed_chunk * 100 / sum_compressed_chunk))
+ # Assume ratio will be the same for the entire file
+ estimated_compressed_file_size=$(( file_size * 100 / current_ratio))
+
# Accumulate the total uncompressed and compressed byte counts
total_uncompressed_size=$((total_uncompressed_size + sum_uncompressed_chunk))
total_compressed_size=$((total_compressed_size + sum_compressed_chunk))
+
+ # Accumulate the estimated uncompressed and compressed byte counts
+ total_uncompressed_size_estimated=$((total_uncompressed_size_estimated +
+ file_size))
+ total_compressed_size_estimated=$((total_compressed_size_estimated +
+ estimated_compressed_file_size))
}
-# Calculate compression ratio from compressed chunks (value > 1)
-calculate_ratio() {
- local ratio=$((total_uncompressed_size * 100 / total_compressed_size))
+# Calculate compression ratio from estimated compressed file (value > 1)
+calculate_estimated_ratio() {
+ local ratio=$((total_uncompressed_size_estimated * 100 /
+ total_compressed_size_estimated))
printf "%u.%02u" $((ratio / 100)) $((ratio % 100))
}
{
local ratio=$1
- printf "%d" $(echo "scale=0; $size_of_all_files / $compression_ratio" | bc)
+ printf "%d" $(echo "scale=0; $size_of_all_files / $compression_ratio_estimated" | bc)
}
print_size() {
total_files_scanned % lines == 0 ||
last + interval < SECONDS) )); then
if ((total_files_scanned != total_file_count)); then
- echo -ne "${cr}Sampled $total_files_scanned/$total_file_count files so far, estimated compression ratio $(calculate_ratio)x...${lf}"
+ echo -ne "${cr}Sampled $total_files_scanned/$total_file_count files so far, estimated compression ratio $(calculate_estimated_ratio)x...${lf}"
else
- echo -ne "${cr}Sampled $total_files_scanned files so far, estimated compression ratio $(calculate_ratio)x...${lf}"
+ echo -ne "${cr}Sampled $total_files_scanned files so far, estimated compression ratio $(calculate_estimated_ratio)x...${lf}"
fi
last=$SECONDS
fi
echo "Total uncompressed size of sampled data: $(print_size $total_uncompressed_size)"
echo "Total compressed size of sampled data: $(print_size $total_compressed_size)"
echo "Compressed size as percentage of uncompressed size: $(calculate_pct)"
-compression_ratio=$(calculate_ratio)
-echo "Compression ratio of sampled data: ${compression_ratio}x"
+compression_ratio_estimated=$(calculate_estimated_ratio)
+echo "Estimated compression ratio of sampled files: ${compression_ratio_estimated}x"
if (( total_files_scanned < total_file_count )); then
size_of_all_files=$((total_file_size * total_file_count / total_files_scanned))
echo "Estimated size of all $total_file_count files: $(print_size $size_of_all_files)"