Skip to content

Commit

Permalink
Replace error for magic number-based file type inference failure with…
Browse files Browse the repository at this point in the history
… extension-based file type inference and add warning
  • Loading branch information
johanmazelanssi authored and chifflier committed Aug 1, 2024
1 parent 9d643a1 commit e26e9c9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pcap-rewrite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate infer;
extern crate lz4;

use std::fs::File;
use std::io::{self, Error, ErrorKind, Read, Seek};
use std::io::{self, Error, Read, Seek};
use std::path::Path;

use flate2::read::GzDecoder;
Expand Down Expand Up @@ -169,8 +169,16 @@ fn get_reader(input_filename: &str) -> io::Result<Box<dyn Read>> {
}
"custom/pcap" => Ok(Box::new(file) as Box<dyn io::Read>),
_ => {
error!("Could not infer type '{}'", input_filename);
Err(Error::new(ErrorKind::Other, "Could not infer type"))
warn!("Could not infer file type '{}'", input_filename);
if input_filename.ends_with(".gz") {
Ok(Box::new(GzDecoder::new(file)))
} else if input_filename.ends_with(".xz") {
Ok(Box::new(XzDecoder::new(file)))
} else if input_filename.ends_with(".lz4") {
Ok(Box::new(lz4::Decoder::new(file)?))
} else {
Ok(Box::new(file) as Box<dyn io::Read>)
}
}
};

Expand Down

0 comments on commit e26e9c9

Please sign in to comment.