Skip to content

Commit

Permalink
Release 0.6.2
Browse files Browse the repository at this point in the history
* Upgrades the zip dependency to version 0.6.2
  • Loading branch information
matzefriedrich committed Sep 3, 2023
1 parent ce3cf75 commit e9c1ea6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "zip-extensions"
version = "0.6.1"
version = "0.6.2"
authors = ["Matthias Friedrich <[email protected]>"]
edition = "2018"
edition = "2021"
description = "An extension crate for zip."
readme = "README.md"
repository = "https://github.com/matzefriedrich/zip-extensions-rs"
Expand All @@ -15,4 +15,4 @@ exclude = [
]

[dependencies]
zip = "0.5"
zip = "0.6.2"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 - 2021 Matthias Friedrich
Copyright (c) 2020 - 2023 Matthias Friedrich

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Add the following dependencies to the `Cargo.toml` file.

````toml
[dependencies]
zip = "0.5"
zip = "0.6"
zip-extensions = "0.6"
````

Expand Down
14 changes: 14 additions & 0 deletions src/file_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,17 @@ pub(crate) fn make_relative_path(root: &PathBuf, current: &PathBuf) -> PathBuf {
}
result
}

// Returns a String representing the given Path.
pub(crate) fn path_as_string(path: &std::path::Path) -> String {
let mut path_str = String::new();
for component in path.components() {
if let std::path::Component::Normal(os_str) = component {
if !path_str.is_empty() {
path_str.push('/');
}
path_str.push_str(&*os_str.to_string_lossy());
}
}
path_str
}
6 changes: 3 additions & 3 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<R: Read + io::Seek> ZipArchiveExtensions for ZipArchive<R> {

for file_number in 0..self.len() {
let mut next: ZipFile = self.by_index(file_number)?;
let sanitized_name = next.sanitized_name();
let sanitized_name = next.mangled_name();
if next.is_dir() {
let extracted_folder_path = target_directory.join(sanitized_name);
std::fs::create_dir_all(extracted_folder_path)?;
Expand Down Expand Up @@ -157,13 +157,13 @@ impl<R: Read + io::Seek> ZipArchiveExtensions for ZipArchive<R> {

fn entry_path(&mut self, file_number: usize) -> ZipResult<PathBuf> {
let next: ZipFile = self.by_index(file_number)?;
Ok(next.sanitized_name())
Ok(next.mangled_name())
}

fn file_number(&mut self, entry_path: &PathBuf) -> Option<usize> {
for file_number in 0..self.len() {
if let Ok(next) = self.by_index(file_number) {
let sanitized_name = next.sanitized_name();
let sanitized_name = next.mangled_name();
if sanitized_name == *entry_path {
return Some(file_number);
}
Expand Down
6 changes: 3 additions & 3 deletions src/write.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::file_utils::make_relative_path;
use crate::file_utils::{make_relative_path, path_as_string};
use std::fs::File;
use std::io;
use std::io::{Read, Write};
Expand Down Expand Up @@ -62,12 +62,12 @@ impl<W: Write + io::Seek> ZipWriterExtensions for ZipWriter<W> {
let mut f = File::open(&entry_path)?;
f.read_to_end(&mut buffer)?;
let relative_path = make_relative_path(&directory, &entry_path);
self.start_file_from_path(&relative_path, options)?;
self.start_file(path_as_string(&relative_path), options)?;
self.write_all(buffer.as_ref())?;
buffer.clear();
} else if entry_metadata.is_dir() {
let relative_path = make_relative_path(&directory, &entry_path);
self.add_directory_from_path(&relative_path, options)?;
self.add_directory(path_as_string(&relative_path), options)?;
paths_queue.push(entry_path.clone());
}
}
Expand Down

0 comments on commit e9c1ea6

Please sign in to comment.