···2727 "gzip"
2828 }
29293030+ /// Generate a default extracted filename
3131+ /// gzip does not support extracting to a directory, so we return a default filename
3232+ fn default_extracted_filename(&self, in_path: &std::path::Path) -> String {
3333+ // If the file has no extension, return a default filename
3434+ if in_path.extension().is_none() {
3535+ return "archive".to_string();
3636+ }
3737+ // Otherwise, return the filename without the extension
3838+ in_path.file_stem().unwrap().to_str().unwrap().to_string()
3939+ }
4040+3041 fn compress(&self, input: CmprssInput, output: CmprssOutput) -> Result<(), io::Error> {
3142 if let CmprssOutput::Path(out_path) = &output {
3243 if out_path.is_dir() {
···23232424 // Generate the default extracted filename
2525 fn default_extracted_filename(&self, in_path: &Path) -> String {
2626+ // If the file has no extension, return the current directory
2727+ if in_path.extension().is_none() {
2828+ return ".".to_string();
2929+ }
3030+ // Otherwise, return the filename without the extension
2631 in_path.file_stem().unwrap().to_str().unwrap().to_string()
2732 }
2833
+45-1
tests/cli.rs
···11use assert_cmd::prelude::*;
22use assert_fs::prelude::*;
33use predicates::prelude::*;
44-use std::process::Command;
44+use std::{
55+ fs::File,
66+ process::{Command, Stdio},
77+};
5869/// Tar roundtrip with a single file
710///
···172175173176 Ok(())
174177}
178178+179179+/// Gzip roundtrip using stdin
180180+/// Compressing: input = stdin, output = archive.gz
181181+/// Extracting: input = archive.gz, output = stdout
182182+#[test]
183183+fn gzip_roundtrip_stdin() -> Result<(), Box<dyn std::error::Error>> {
184184+ let file = assert_fs::NamedTempFile::new("test.txt")?;
185185+ file.write_str("garbage data for testing")?;
186186+ let working_dir = assert_fs::TempDir::new()?;
187187+ let archive = working_dir.child("test.txt.gz");
188188+ archive.assert(predicate::path::missing());
189189+190190+ // Pipe file to stdin
191191+ let mut compress = Command::cargo_bin("cmprss")?;
192192+ compress
193193+ .current_dir(&working_dir)
194194+ .arg("gzip")
195195+ .arg("--compression")
196196+ .arg("0")
197197+ // TODO: add a flag to ignore just stdout so we can test each side
198198+ .arg("test.txt.gz")
199199+ .stdin(Stdio::from(File::open(file.path())?));
200200+ compress.assert().success();
201201+ archive.assert(predicate::path::is_file());
202202+203203+ let mut extract = Command::cargo_bin("cmprss")?;
204204+ extract
205205+ .current_dir(&working_dir)
206206+ .arg("gzip")
207207+ .arg("--ignore-pipes")
208208+ .arg("--extract")
209209+ .arg(archive.path());
210210+ extract.assert().success();
211211+212212+ // Assert the files are identical
213213+ working_dir
214214+ .child("test.txt")
215215+ .assert(predicate::path::eq_file(file.path()));
216216+217217+ Ok(())
218218+}