use std::io::Write; use std::path::Path; use munzip::MuError; pub fn write_file(filename: &String, data: &Vec) -> Result<(), MuError> { let path = Path::new(&filename); if filename.ends_with("/") { if !path.exists() { std::fs::create_dir_all(path) .map_err(|_| MuError(format!("failed to create dir '{:?}'", path).to_string()))?; } return Ok(()); } // is a dir, or empty filename if path.ends_with("/") || path == Path::new("") { return Ok(()); } let mut file = std::fs::File::create(path).unwrap(); file.write_all(&data).unwrap(); Ok(()) }