zip-extensions 0.2.0

An extension create for zip.
Documentation

zip-extensions-rs

Build status Crates.io

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.

Usage examples

Configure dependencies

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.

Extracting an archive to a directory

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();

Creating an archive from a directory

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()