use v5.10;
use IO::Compress::Zip qw(zip $ZipError);
my @list = ( 'file_A.txt', 'file_B.txt' );
zip \@list => 'name.zip'ordie"zip failed: $ZipError\n";
Core module IO::Compress::Zip (available since v5.9.4) provides a zip function that takes a reference to a list (i.e. \@list not @list) and the name of the zip file. If it fails, $ZipError contains the error message. See documentation for details.
let path = std::path::Path::new(_name);
let file = std::fs::File::create(&path).unwrap();
let mut zip = zip::ZipWriter::new(file); zip.start_file("readme.txt", FileOptions::default())?;
zip.write_all(b"Hello, World!\n")?;
zip.finish()?;
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(())
}