Skip to main content

Compressor

Trait Compressor 

Source
pub trait Compressor: Send + Sync {
    // Required methods
    fn compression_type(&self) -> CompressionType;
    fn compress(&self, input: &[u8]) -> Result<Vec<u8>>;
    fn decompress(&self, input: &[u8], max_output: usize) -> Result<Vec<u8>>;
    fn name(&self) -> &'static str;
}
Expand description

Trait for pluggable compression algorithms.

Implement this trait to add custom compression support to Crous.

struct MyCompressor;

impl Compressor for MyCompressor {
    fn compression_type(&self) -> CompressionType { /* ... */ }
    fn compress(&self, input: &[u8]) -> Result<Vec<u8>> { /* ... */ }
    fn decompress(&self, input: &[u8], max_output: usize) -> Result<Vec<u8>> { /* ... */ }
}

Required Methods§

Source

fn compression_type(&self) -> CompressionType

The compression type identifier for block headers.

Source

fn compress(&self, input: &[u8]) -> Result<Vec<u8>>

Compress the input data.

Source

fn decompress(&self, input: &[u8], max_output: usize) -> Result<Vec<u8>>

Decompress the input data. max_output is the maximum allowed output size (for DoS mitigation).

Source

fn name(&self) -> &'static str

The human-readable name of this compressor.

Implementors§