Skip to content

Commit c39be95

Browse files
authored
fix: panic when no output extension (#34)
1 parent 7142676 commit c39be95

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/parsers/fastx.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ pub fn parse_fastq(
4848
}
4949

5050
fn infer_compression(file_path: &PathBuf) -> niffler::compression::Format {
51-
let path = Path::new(&file_path);
52-
let ext = path.extension().unwrap().to_str().unwrap();
53-
match ext {
54-
"gz" => niffler::compression::Format::Gzip,
55-
"bz2" => niffler::compression::Format::Bzip,
51+
let path = Path::new(file_path);
52+
match path
53+
.extension()
54+
.and_then(|ext| ext.to_str())
55+
.map(|ext| ext.to_ascii_lowercase())
56+
{
57+
Some(ref ext) if ext == "gz" => niffler::compression::Format::Gzip,
58+
Some(ref ext) if ext == "bz2" => niffler::compression::Format::Bzip,
5659
_ => niffler::compression::Format::No,
5760
}
5861
}
@@ -157,6 +160,22 @@ mod tests {
157160
assert_eq!(compression, niffler::compression::Format::No);
158161
}
159162

163+
#[test]
164+
fn test_infer_compression_no_extension() {
165+
let file_path = PathBuf::from("test");
166+
let compression = infer_compression(&file_path);
167+
168+
assert_eq!(compression, niffler::compression::Format::No);
169+
}
170+
171+
#[test]
172+
fn test_infer_compression_uppercase_extension() {
173+
let file_path = PathBuf::from("test.GZ");
174+
let compression = infer_compression(&file_path);
175+
176+
assert_eq!(compression, niffler::compression::Format::Gzip);
177+
}
178+
160179
#[test]
161180
fn test_parse_fastq_with_matches() {
162181
let dir = tempdir().unwrap();

0 commit comments

Comments
 (0)