Logo

Programming-Idioms

History of Idiom 217 > diff from v5 to v6

Edit summary for version 6 by swedebugia:
New Rust implementation by user [swedebugia]

Version 5

2020-04-16, 16:35:52

Version 6

2020-04-16, 16:37:55

Idiom #217 Create a Zip archive

Create a zip-file with filename name and add the files listed in list to that zip-file.

Idiom #217 Create a Zip archive

Create a zip-file with filename name and add the files listed in list to that zip-file.

Extra Keywords
zip
Extra Keywords
zip
Imports
use zip::write::FileOptions;
Code
fn zip(_name: &str, _list: Vec<&str>) -> zip::result::ZipResult<()>
{
    let path = std::path::Path::new(_name);
    let file = std::fs::File::create(&path).unwrap();
    let mut zip = zip::ZipWriter::new(file);
    for i in _list.iter() {
        zip.start_file(i as &str, FileOptions::default())?;
    }
    zip.finish()?;
    Ok(())
}
Comments bubble
Note: This function does not write any contents to the files.
Doc URL
http://mvdnes.github.io/rust-docs/zip-rs/zip/index.html
Origin
https://github.com/mvdnes/zip-rs/blob/master/examples/write_sample.rs