#zip-archive #directory #create #file #path #io #follows

zip-dir

A crate providing an easy way to create a ZIP archive of a directory

1 unstable release

0.1.0 Sep 7, 2019

#82 in #zip-archive

MIT license

3KB

zip-dir

crates.io Docs

Usage

[dependencies]
zip-dir = "0.1"

This crate provides the zip_dir function which can be used as follows:

use std::fs::File;
use std::io;
use std::path::Path;

use zip_dir::zip_dir;

fn run() -> io::Result<()> {
    let path = Path::new(".");
    let file = File::create("archive.zip")?;

    // See http://mvdnes.github.io/rust-docs/zip-rs/zip/write/struct.FileOptions.html for options
    // Passing None uses the default options with no compression
    let options = None;

    // zip_dir returns its second parameter wrapped in a Result if successful
    let _file = zip_dir(path, file, options)?;

    Ok(())
}

fn main() {
    match run() {
        Ok(()) => println!("Wrote archive.zip"),
        Err(e) => eprintln!("Error: {}", e)
    }
}

Dependencies

~1.8–2.9MB
~48K SLoC