pub enum Compress {
Gzip,
Deflate,
Br,
Unknown,
}
Expand description
Represents different compression algorithms supported by the library.
Variants§
Gzip
Gzip compression algorithm.
Deflate
Deflate compression algorithm.
Br
Brotli compression algorithm.
Unknown
Represents an unknown or unsupported compression algorithm.
Implementations§
Source§impl Compress
Provides methods for interacting with the Compress
enum.
impl Compress
Provides methods for interacting with the Compress
enum.
Sourcepub fn is_unknown(&self) -> bool
pub fn is_unknown(&self) -> bool
Checks if the current instance is of the Unknown
type.
This method compares the current instance with the Unknown
variant of the enum.
It returns true
if the instance is of type Unknown
, otherwise false
.
§Returns
true
if the instance is of typeUnknown
.false
otherwise.
Sourcepub fn from(
header: &HashMap<String, String, BuildHasherDefault<Hasher>>,
) -> Compress
pub fn from( header: &HashMap<String, String, BuildHasherDefault<Hasher>>, ) -> Compress
Extracts the compression type from an HTTP header.
This function looks for the Content-Encoding
header in the provided Header
and attempts
to parse it into a Compress
enum value.
§Arguments
header
- The HTTP header from which the compression type is to be extracted.
§Returns
- The
Compress
value corresponding to theContent-Encoding
header, orCompress::Unknown
if the header does not match any known compression types.
Sourcepub fn decode<'a>(&self, data: &'a [u8], buffer_size: usize) -> Cow<'a, Vec<u8>>
pub fn decode<'a>(&self, data: &'a [u8], buffer_size: usize) -> Cow<'a, Vec<u8>>
Decompresses the given data based on the selected compression algorithm.
This method takes a byte slice of compressed data and decompresses it using one of the following compression algorithms, depending on the variant of the enum it is called on:
Gzip
- Decompresses using Gzip compression.Deflate
- Decompresses using Deflate compression.Br
- Decompresses using Brotli compression.Unknown
- Returns the input data as-is (no decompression performed).
§Parameters
data
- A reference to a byte slice (&[u8]
) containing the compressed data to be decoded.buffer_size
- The buffer size to use for the decompression process. A larger buffer size can improve performance for larger datasets.
§Returns
Cow<Vec<u8>>
- The decompressed data as aCow<Vec<u8>>
. If the compression algorithm isUnknown
, the original data is returned unchanged, as a borrowed reference. Otherwise, the decompressed data is returned as an ownedVec<u8>
.
Sourcepub fn encode<'a>(&self, data: &'a [u8], buffer_size: usize) -> Cow<'a, Vec<u8>>
pub fn encode<'a>(&self, data: &'a [u8], buffer_size: usize) -> Cow<'a, Vec<u8>>
Compresses the given data based on the selected compression algorithm.
This method takes a byte slice of data and compresses it using one of the following compression algorithms, depending on the variant of the enum it is called on:
Gzip
- Compresses using Gzip compression.Deflate
- Compresses using Deflate compression.Br
- Compresses using Brotli compression.Unknown
- Returns the input data as-is (no compression performed).
§Parameters
data
- A reference to a byte slice (&[u8]
) containing the data to be compressed.buffer_size
- The buffer size to use for the compression process. A larger buffer size can improve performance for larger datasets.
§Returns
Cow<Vec<u8>>
- The compressed data as aCow<Vec<u8>>
. If the compression algorithm isUnknown
, the original data is returned unchanged, as a borrowed reference. Otherwise, the compressed data is returned as an ownedVec<u8>
.
Trait Implementations§
Source§impl Display for Compress
Implements the Display
trait for the Compress
enum.
impl Display for Compress
Implements the Display
trait for the Compress
enum.
This allows the Compress
enum variants to be formatted as strings,
typically used for outputting the Content-Encoding
header value.
Source§impl FromStr for Compress
Enables parsing a string into a Compress
enum variant.
impl FromStr for Compress
Enables parsing a string into a Compress
enum variant.
This implementation allows converting string representations of compression
algorithms (like “gzip”, “deflate”, “br”) into their corresponding Compress
enum variants. If the string does not match any known compression types,
it defaults to Compress::Unknown
.
Source§fn from_str(data: &str) -> Result<Compress, <Compress as FromStr>::Err>
fn from_str(data: &str) -> Result<Compress, <Compress as FromStr>::Err>
Parses a string into a Compress
enum variant.
This method converts string representations of compression algorithms
(case-insensitive) into their corresponding Compress
enum variants.
Unknown strings are converted to Compress::Unknown
.
§Arguments
data
- The string to parse, which should be a compression algorithm name.
§Returns
Result<Self, Self::Err>
- ReturnsOk
with the matchingCompress
variant, orOk(Compress::Unknown)
for unknown strings. Never returnsErr
.