diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6738b0b..876bfb1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,9 +2,19 @@ name: Rust on: push: - branches: [ master ] + branches: + - master + - feature/* + - fix/* + pull_request: - branches: [ master ] + branches: + - master + - feature/* + - fix/* + +env: + CARGO_TERM_COLOR: always jobs: build: @@ -13,7 +23,9 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Build run: cargo build --verbose + - name: Run tests run: cargo test --verbose diff --git a/CHANGELOG.md b/CHANGELOG.md index 9922373..5426bb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.8.0] - 2024-06-02 + +The project follows the active development of the `zip` crate and has thus been updated to work with **zip2**; this release comes with several breaking changes in the `write` module. + +### Changed + +- Upgrades the `zip` package reference; uses the new **zip2** version +- Adds `FileOptionExtension` type argument to the `zip_create_from_directory_with_options` trait and implementation to address zip2 build issues +- Removes the `mut` modifier from the `ZipWriterExtensions` to fix issues + + ## [0.7.0] - 2024-06-01 ### Changed diff --git a/Cargo.toml b/Cargo.toml index f2297d7..b4d384d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zip-extensions" -version = "0.7.0" +version = "0.8.0" authors = ["Matthias Friedrich "] edition = "2021" description = "An extension crate for zip." @@ -15,4 +15,4 @@ exclude = [ ] [dependencies] -zip = "0.6.6" +zip = "2.1.1" diff --git a/README.md b/README.md index 2f7f88d..5f6ede1 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ # zip-extensions-rs ![Rust](https://github.com/matzefriedrich/zip-extensions-rs/workflows/Rust/badge.svg) -[![Build status](https://ci.appveyor.com/api/projects/status/41lavncr30iyv5rk/branch/master?svg=true)](https://ci.appveyor.com/project/matzefriedrich/zip-extensions-rs/branch/master) ![Crates.io](https://img.shields.io/crates/v/zip-extensions) -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. +An extension crate for https://github.com/zip-rs/zip2 that provides high-level functions for common ZIP tasks, such as extracting archives to a directory. ## Usage examples @@ -15,11 +14,11 @@ Add the following dependencies to the `Cargo.toml` file. ````toml [dependencies] -zip = "0.6" -zip-extensions = "0.6" +zip = "2.1.1" +zip-extensions = "0.8.0" ```` -See https://github.com/mvdnes/zip-rs fur further information about `zip` dependencies. +See https://github.com/zip-rs/zip2 fur further information about `zip` dependencies. ### Extracting an archive to a directory @@ -72,7 +71,7 @@ use zip_extensions::write::ZipWriterExtensions; ... let file = File::create(archive_file)?; -let mut zip = ZipWriter::new(file); +let zip = ZipWriter::new(file); zip.create_from_directory(&source_path)?; ```` diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 00d64dc..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,8 +0,0 @@ -image: Ubuntu -install: - - sh: | - sudo apt-get -y update && sudo apt-get -y upgrade && sudo apt-get -y install curl mingw-w64 - sudo curl https://sh.rustup.rs -sSf | sh -s -- -y - export PATH="$HOME/.cargo/bin:$PATH" -build_script: - - sh: cargo build diff --git a/src/write.rs b/src/write.rs index 313d9ca..799d468 100644 --- a/src/write.rs +++ b/src/write.rs @@ -5,57 +5,60 @@ use std::path::PathBuf; use zip::{CompressionMethod, ZipWriter}; use zip::result::ZipResult; -use zip::write::FileOptions; +use zip::write::{FileOptionExtension, FileOptions, SimpleFileOptions}; use crate::file_utils::{make_relative_path, path_as_string}; /// Creates a zip archive that contains the files and directories from the specified directory. pub fn zip_create_from_directory(archive_file: &PathBuf, directory: &PathBuf) -> ZipResult<()> { - let options = FileOptions::default().compression_method(CompressionMethod::Stored); + let options = SimpleFileOptions::default().compression_method(CompressionMethod::Stored); zip_create_from_directory_with_options(archive_file, directory, |_| options) } /// Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level. -pub fn zip_create_from_directory_with_options( +pub fn zip_create_from_directory_with_options( archive_file: &PathBuf, directory: &PathBuf, - options_map: F, + cb_file_options: F, ) -> ZipResult<()> where - F: Fn(&PathBuf) -> FileOptions, + T: FileOptionExtension, + F: Fn(&PathBuf) -> FileOptions, { let file = File::create(archive_file)?; - let mut zip_writer = ZipWriter::new(file); - zip_writer.create_from_directory_with_options(directory, options_map) + let zip_writer = ZipWriter::new(file); + zip_writer.create_from_directory_with_options(directory, cb_file_options) } pub trait ZipWriterExtensions { /// Creates a zip archive that contains the files and directories from the specified directory. - fn create_from_directory(&mut self, directory: &PathBuf) -> ZipResult<()>; + fn create_from_directory(self, directory: &PathBuf) -> ZipResult<()>; /// Creates a zip archive that contains the files and directories from the specified directory, uses the specified compression level. - fn create_from_directory_with_options( - &mut self, + fn create_from_directory_with_options( + self, directory: &PathBuf, - options_map: F, + cb_file_options: F, ) -> ZipResult<()> where - F: Fn(&PathBuf) -> FileOptions; + T: FileOptionExtension, + F: Fn(&PathBuf) -> FileOptions; } impl ZipWriterExtensions for ZipWriter { - fn create_from_directory(&mut self, directory: &PathBuf) -> ZipResult<()> { - let options = FileOptions::default().compression_method(CompressionMethod::Stored); + fn create_from_directory(self, directory: &PathBuf) -> ZipResult<()> { + let options = SimpleFileOptions::default().compression_method(CompressionMethod::Stored); self.create_from_directory_with_options(directory, |_| options) } - fn create_from_directory_with_options( - &mut self, + fn create_from_directory_with_options( + mut self, directory: &PathBuf, - options_map: F, + cb_file_options: F, ) -> ZipResult<()> where - F: Fn(&PathBuf) -> FileOptions, + T: FileOptionExtension, + F: Fn(&PathBuf) -> FileOptions, { let mut paths_queue: Vec = vec![]; paths_queue.push(directory.clone()); @@ -67,7 +70,7 @@ impl ZipWriterExtensions for ZipWriter { for entry in directory_entry_iterator { let entry_path = entry?.path(); - let file_options = options_map(&entry_path); + let file_options = cb_file_options(&entry_path); let entry_metadata = std::fs::metadata(entry_path.clone())?; if entry_metadata.is_file() { let mut f = File::open(&entry_path)?;