matzefriedrich / zip-extensions-rs

Provides extensions for the zip crate
MIT License
20 stars 12 forks source link

Add support for setting per-item `FileOptions` (mapping) #13

Closed m4heshd closed 4 months ago

m4heshd commented 6 months ago

This PR implements the feature discussed in #12, allowing an instance of FileOptions to be set for each file or directory processed by create_from_directory_with_options(). As mentioned there, this API refactor would be a breaking change.

Current usage of the API:

let mut zip = ZipWriter::new(file);

// This has the limitation of only allowing one configuration for all the files and directories.
zip.create_from_directory_with_options(
    &PathBuf::from(&source_dir),
    FileOptions::default(),
);

API usage with this PR:

let mut zip = ZipWriter::new(file);

zip.create_from_directory_with_options(&PathBuf::from(&source_dir), |file: &PathBuf| {
    if file.eq(&PathBuf::from("dir/my_executable")) {
        FileOptions::default().unix_permissions(0o775)
    } else {
        FileOptions::default()
    }
});