should_compress

Function should_compress 

Source
pub fn should_compress(
    data: &Bytes,
    algorithm: CompressionAlgorithm,
    level: u8,
) -> Result<bool>
Expand description

Check if data is worth compressing based on size and estimated ratio

Returns true if compression would likely save significant space. Uses a threshold of 20% savings and minimum size of 1KB.

ยงExample

use ipfrs_core::utils::should_compress;
use ipfrs_core::CompressionAlgorithm;
use bytes::Bytes;

let small_data = Bytes::from_static(b"Hello"); // Too small
assert!(!should_compress(&small_data, CompressionAlgorithm::Zstd, 3).unwrap());

let large_repetitive = Bytes::from("a".repeat(10000)); // Worth compressing
assert!(should_compress(&large_repetitive, CompressionAlgorithm::Zstd, 3).unwrap());