An extension crate for https://github.com/mvdnes/zip-rs that provides high-level functions for common ZIP tasks, such as extracting archives to a directory.
Add the following dependencies to the Cargo.toml
file.
[dependencies]
zip = "0.5.5"
zip-extensions = "0.1.4"
See https://github.com/mvdnes/zip-rs fur further information about zip
dependencies.
The ZipArchiveExtensions
trait provides the extract
method that can be used to unzip an archive to a directory.
use std::fs::File;
use zip_extensions::read_extensions::ZipArchiveExtensions;
...
let file = File::create(archive_file).unwrap();
let mut archive = zip::ZipArchive::new(file).unwrap();
archive.extract(&target_path).unwrap();
The ZipWriterExtensions
trait provides the create_from_directory
and create_from_directory_with_options
methods that can be used to add an entire directory hierarchy to an archive.
use zip::ZipWriter;
use zip_extensions::write_extensions::ZipWriterExtensions;
...
let file = File::create(archive_file).unwrap();
let mut zip = ZipWriter::new(file);
zip.create_from_directory(&source_path).unwrap()