1use ignore::Walk;
2use std::io::Write;
3use zip::write::{FileOptions, ZipWriter};
4
5pub fn zip_dir(path: &str, zip_file_name: &str) {
6 let mut zip = ZipWriter::new(std::fs::File::create(zip_file_name).unwrap());
7 for entry in Walk::new(path) {
8 let entry = entry.unwrap();
9 if entry.file_name().to_str().unwrap() == zip_file_name {
10 continue;
11 }
12 if entry.path().is_dir() {
13 zip.add_directory(entry.path().to_str().unwrap(), FileOptions::default());
14 } else {
15 zip.start_file_from_path(&entry.path(), FileOptions::default())
16 .unwrap();
17 zip.write_all(std::fs::read(entry.path()).unwrap().as_slice())
18 .unwrap();
19 }
20 }
21}