pub struct StorageCompressionPipeline {
pub config: PipelineConfig,
pub total_compressed: u64,
pub total_bytes_in: u64,
pub total_bytes_out: u64,
pub algo_counters: HashMap<String, u64>,
}Expand description
Multi-stage compression pipeline with content-aware algorithm selection.
§Example
use ipfrs_storage::compression_pipeline::{
StorageCompressionPipeline, PipelineConfig, CompressionHint,
};
let mut pipeline = StorageCompressionPipeline::new(PipelineConfig::default());
let data = b"aaaaaabbbbbbcccccccccdddddddddeeeeeeeeeee";
let result = pipeline.compress(data, CompressionHint::Binary);
let recovered = pipeline.decompress(&result.data, &result.algo).unwrap();
assert_eq!(&recovered, data);Fields§
§config: PipelineConfigPipeline configuration.
total_compressed: u64Number of successful compress calls.
total_bytes_in: u64Total raw bytes fed into the pipeline.
total_bytes_out: u64Total compressed bytes emitted by the pipeline.
algo_counters: HashMap<String, u64>Per-algorithm usage counters.
Implementations§
Source§impl StorageCompressionPipeline
impl StorageCompressionPipeline
Sourcepub fn new(config: PipelineConfig) -> Self
pub fn new(config: PipelineConfig) -> Self
Create a new pipeline with the supplied configuration.
Sourcepub fn compress(
&mut self,
data: &[u8],
_hint: CompressionHint,
) -> CompressionResult
pub fn compress( &mut self, data: &[u8], _hint: CompressionHint, ) -> CompressionResult
Compress data using the first pipeline stage whose conditions are met.
Stages are tried in the order defined in PipelineConfig::stages. A
stage is skipped if:
data.len() < stage.min_input_size, orconfig.enable_ratio_checkistrueand the resulting ratio exceedsstage.max_ratio.
If no stage accepts the data, the fallback_algo is used.
Sourcepub fn decompress(
&self,
data: &[u8],
algo: &CompressionAlgo,
) -> Result<Vec<u8>, CompressionError>
pub fn decompress( &self, data: &[u8], algo: &CompressionAlgo, ) -> Result<Vec<u8>, CompressionError>
Decompress data using the specified algorithm.
Sourcepub fn compress_with_algo(&self, data: &[u8], algo: &CompressionAlgo) -> Vec<u8> ⓘ
pub fn compress_with_algo(&self, data: &[u8], algo: &CompressionAlgo) -> Vec<u8> ⓘ
Compress data with a specific algorithm, returning the raw bytes.
Sourcepub fn detect_hint(data: &[u8]) -> CompressionHint
pub fn detect_hint(data: &[u8]) -> CompressionHint
Detect content hint from the first few bytes of data.
Sourcepub fn auto_compress(&mut self, data: &[u8]) -> CompressionResult
pub fn auto_compress(&mut self, data: &[u8]) -> CompressionResult
Automatically detect the content hint and then compress.
Sourcepub fn pipeline_stats(&self) -> PipelineStats
pub fn pipeline_stats(&self) -> PipelineStats
Return a snapshot of the current pipeline statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StorageCompressionPipeline
impl RefUnwindSafe for StorageCompressionPipeline
impl Send for StorageCompressionPipeline
impl Sync for StorageCompressionPipeline
impl Unpin for StorageCompressionPipeline
impl UnsafeUnpin for StorageCompressionPipeline
impl UnwindSafe for StorageCompressionPipeline
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more