Skip to content

Commit

Permalink
Merge pull request #44 from zip-rs/oldpr421
Browse files Browse the repository at this point in the history
fix: Improve ErrorKind in ZipError to io::Error conversion
  • Loading branch information
Pr0methean authored Apr 30, 2024
2 parents b3991bb + 686f6f1 commit 90fd957
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Library to support the reading and writing of zip files.
"""
edition = "2021"
exclude = ["tests/**", "examples/**", ".github/**", "fuzz/**"]
build = "src/build.rs"

[workspace.dependencies]
time = { version = "0.3.36", default-features = false }
Expand Down
Empty file added fuzz/corpus/seed/short_read.zip
Empty file.
7 changes: 7 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::env::var;

fn main() {
if var("CARGO_FEATURE_DEFLATE_MINIZ").is_ok() {
println!("cargo:warning=Feature `deflate-miniz` is deprecated; replace it with `deflate`");
}
}
10 changes: 9 additions & 1 deletion src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ impl ZipError {

impl From<ZipError> for io::Error {
fn from(err: ZipError) -> io::Error {
io::Error::new(io::ErrorKind::Other, err)
let kind = match &err {
ZipError::Io(err) => err.kind(),
ZipError::InvalidArchive(_) => io::ErrorKind::InvalidData,
ZipError::UnsupportedArchive(_) => io::ErrorKind::Unsupported,
ZipError::FileNotFound => io::ErrorKind::NotFound,
ZipError::InvalidPassword => io::ErrorKind::InvalidInput,
};

io::Error::new(kind, err)
}
}

Expand Down

0 comments on commit 90fd957

Please sign in to comment.