Skip to content

Commit

Permalink
chore: update tests to use preferred method
Browse files Browse the repository at this point in the history
  • Loading branch information
Plecra committed Sep 12, 2020
1 parent 1030033 commit a35c8ff
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
14 changes: 6 additions & 8 deletions examples/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ fn real_main() -> i32 {

for i in 0..archive.len() {
let mut file = archive.by_index(i).unwrap();
#[allow(deprecated)]
let outpath = file.sanitized_name();
let outpath = match file.name_as_child() {
Some(path) => path,
None => continue,
};

{
let comment = file.comment();
Expand All @@ -29,17 +31,13 @@ fn real_main() -> i32 {
}

if (&*file.name()).ends_with('/') {
println!(
"File {} extracted to \"{}\"",
i,
outpath.as_path().display()
);
println!("File {} extracted to \"{}\"", i, outpath.display());
fs::create_dir_all(&outpath).unwrap();
} else {
println!(
"File {} extracted to \"{}\" ({} bytes)",
i,
outpath.as_path().display(),
outpath.display(),
file.size()
);
if let Some(p) = outpath.parent() {
Expand Down
13 changes: 9 additions & 4 deletions examples/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ fn real_main() -> i32 {

for i in 0..archive.len() {
let file = archive.by_index(i).unwrap();
#[allow(deprecated)]
let outpath = file.sanitized_name();
let outpath = match file.name_as_child() {
Some(path) => path,
None => {
println!("Entry {} has a suspicious path", file.name());
continue;
}
};

{
let comment = file.comment();
Expand All @@ -33,13 +38,13 @@ fn real_main() -> i32 {
println!(
"Entry {} is a directory with name \"{}\"",
i,
outpath.as_path().display()
outpath.display()
);
} else {
println!(
"Entry {} is a file with name \"{}\" ({} bytes)",
i,
outpath.as_path().display(),
outpath.display(),
file.size()
);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/zip64_large.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,11 @@ fn zip64_large() {

for i in 0..archive.len() {
let mut file = archive.by_index(i).unwrap();
#[allow(deprecated)]
let outpath = file.sanitized_name();
let outpath = file.name_as_child().unwrap();
println!(
"Entry {} has name \"{}\" ({} bytes)",
i,
outpath.as_path().display(),
outpath.display(),
file.size()
);

Expand Down
3 changes: 1 addition & 2 deletions tests/zip_crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ fn encrypted_file() {
.by_index_decrypt(0, "test".as_bytes())
.unwrap()
.unwrap();
#[allow(deprecated)]
let file_name = file.sanitized_name();
let file_name = file.name_as_child().unwrap();
assert_eq!(file_name, std::path::PathBuf::from("test.txt"));

let mut data = Vec::new();
Expand Down

0 comments on commit a35c8ff

Please sign in to comment.