Crate zip_archive
source · [−]Expand description
Zip archive
zip_archive
is a library that archive a directory with a specific compression format.
Supports multi-threading.
Supported Formats
Examples
- Compress root directory with 4 threads.
use std::path::PathBuf;
use zip_archive::Archiver;
let origin = PathBuf::from("./origin");
let dest = PathBuf::from("./dest");
let thread_count = 4;
let mut archiver = Archiver::new();
archiver.push(origin);
archiver.set_destination(dest);
archiver.set_thread_count(thread_count);
match archiver.archive(){
Ok(_) => (),
Err(e) => println!("Cannot archive the directory! {}", e),
};
- Compress each directory using the container’s iterator.
use std::path::PathBuf;
use zip_archive::Archiver;
let origin = PathBuf::from("./origin");
let dest = PathBuf::from("./dest");
let mut archiver = Archiver::new();
archiver.push_from_iter(vec!["./origin/dir1", "./origin/dir2", "./origin/dir3"].into_iter());
archiver.set_destination(dest);
match archiver.archive(){
Ok(_) => (),
Err(e) => println!("Cannot archive the directory! {}", e),
};
- Compress directory with .xz format.
use std::path::PathBuf;
use zip_archive::Format;
use zip_archive::{Archiver, get_dir_list_with_depth};
let origin = PathBuf::from("./origin"); // Change to the wanted directory.
let dest = PathBuf::from("./dest");
let mut archiver = Archiver::new();
archiver.push(origin);
archiver.set_destination(dest);
archiver.set_format(Format::Xz); // == `archiver.set_format_str("xz");`
match archiver.archive(){
Ok(_) => (),
Err(e) => println!("Cannot archive the directory! {}", e),
};
Requirements for 7z format
To use 7z archiving format, you need to install 7z or get the executable depending on the operating system.
Windows 10
- Install 7-Zip.
- Find 7z.exe file in installed program folder and add it to path. Or place it in project root folder.
macOS
- Download 7-Zip console version executable for macOS.
- Place 7zz executable to home directory.
Structs
Archiver struct.
Enums
The enum of formats that currently supported.
Using this enum, you can set the format of archiving method.
Functions
Get list of all subdirectories in the rood directory. Not recursive.
Get a list of directories at a specific depth among all subdirectories of the rood directory.