Skip to content

Commit

Permalink
chore: fixup compression detector
Browse files Browse the repository at this point in the history
Content-Encoding doesn't seem to make sense. So dropping it.
  • Loading branch information
ctron committed Sep 13, 2024
1 parent 8a5c2b4 commit d9d7f8e
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions common/src/compression/detecting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,12 @@ impl Compression {

#[derive(Clone, Debug, Default)]
pub struct Detector<'a> {
/// Content Encoding value from an HTTP header
pub content_encoding: Option<&'a str>,
/// File name
pub file_name: Option<&'a str>,

/// Disable detection by magic bytes
pub disable_magic: bool,

/// Content encodings to ignore.
pub ignore_content_encodings: HashSet<&'a str>,
/// If a content encoding is present, but the encoding is unknown, report as an error
pub fail_unknown_content_encoding: bool,

/// File name extensions to ignore.
pub ignore_file_extensions: HashSet<&'a str>,
/// If a file name is present, but the extension is unknown, report as an error
Expand All @@ -65,26 +58,6 @@ impl<'a> Detector<'a> {
}

pub fn detect(&'a self, #[allow(unused)] data: &[u8]) -> Result<Compression, Error<'a>> {
// detect by content encoding

if let Some(content_encoding) = self.content_encoding {
match content_encoding {
#[cfg(any(feature = "bzip2", feature = "bzip2-rs"))]
"bzip" => return Ok(Compression::Bzip2),
#[cfg(feature = "liblzma")]
"xz" => return Ok(Compression::Xz),
other
if self.fail_unknown_content_encoding
&& !self.ignore_content_encodings.contains(other) =>
{
return Err(Error::Unsupported(other))
}
_ => {
// continue
}
}
}

// detect by file name extension

if let Some(file_name) = self.file_name {
Expand All @@ -98,7 +71,7 @@ impl<'a> Detector<'a> {
}
if self.fail_unknown_file_extension {
if let Some((_, ext)) = file_name.rsplit_once('.') {
if !self.ignore_content_encodings.contains(ext) {
if !self.ignore_file_extensions.contains(ext) {
return Err(Error::Unsupported(ext));
}
}
Expand Down

0 comments on commit d9d7f8e

Please sign in to comment.