diff --git a/Cargo.toml b/Cargo.toml index 022db57..3736e8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,4 @@ dyn-fmt = "0.3.0" colored = "2.0.0" serde = { version = "1.0.125", features = ["derive"] } serde_json = "1.0.64" -zip = { version = "0.5.12", default-features = false } \ No newline at end of file +zip = "0.5.12" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 00f0814..54e210e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -152,8 +152,12 @@ fn main() { let path = Path::new(&file_path); let res = workspace::zip_file(path); - if res.is_none() { - println!("Error zipping {}!", path.to_str().unwrap()); + if let Err(e) = res { + println!( + "Error zipping {}! Error: {}", + path.to_str().unwrap(), + e.to_string().bright_red() + ); return; } diff --git a/src/workspace/zip.rs b/src/workspace/zip.rs index 3d31f60..a6406dd 100644 --- a/src/workspace/zip.rs +++ b/src/workspace/zip.rs @@ -1,23 +1,23 @@ use std::fs::{read, File}; -use std::io::Write; +use std::io::{Error, ErrorKind, Write}; use std::path::Path; -pub fn zip_file(path: &Path) -> Option { - let filename = path.file_name().unwrap().to_str()?; - let path = path.to_str()?; +pub fn zip_file(path: &Path) -> Result { + let filename = path.file_name().unwrap().to_str().ok_or(ErrorKind::Other)?; + let path = path.to_str().ok_or(ErrorKind::Other)?; println!("Zipping {}.", filename); tracing::debug!("Relative path: {}.", path); - let source = read(path).ok()?; - let buf = File::create("source.zip").ok()?; + let source = read(path)?; + let buf = File::create("source.zip")?; let mut zip = zip::ZipWriter::new(buf); let options = - zip::write::FileOptions::default().compression_method(zip::CompressionMethod::Stored); - zip.start_file(filename, options).ok()?; - zip.write(source.as_ref()).ok()?; - zip.finish().ok()?; + zip::write::FileOptions::default().compression_method(zip::CompressionMethod::DEFLATE); + zip.start_file(filename, options)?; + zip.write_all(source.as_ref())?; + zip.finish()?; - Some("source.zip".to_string()) + Ok("source.zip".to_string()) }