1 use std::fs;
2 use std::io::BufReader;
3
main()4 fn main() {
5 std::process::exit(real_main());
6 }
7
real_main() -> i328 fn real_main() -> i32 {
9 let args: Vec<_> = std::env::args().collect();
10 if args.len() < 2 {
11 println!("Usage: {} <filename>", args[0]);
12 return 1;
13 }
14 let fname = std::path::Path::new(&*args[1]);
15 let file = fs::File::open(&fname).unwrap();
16 let reader = BufReader::new(file);
17
18 let mut archive = zip::ZipArchive::new(reader).unwrap();
19
20 for i in 0..archive.len() {
21 let file = archive.by_index(i).unwrap();
22 let outpath = match file.enclosed_name() {
23 Some(path) => path,
24 None => {
25 println!("Entry {} has a suspicious path", file.name());
26 continue;
27 }
28 };
29
30 {
31 let comment = file.comment();
32 if !comment.is_empty() {
33 println!("Entry {} comment: {}", i, comment);
34 }
35 }
36
37 if (*file.name()).ends_with('/') {
38 println!(
39 "Entry {} is a directory with name \"{}\"",
40 i,
41 outpath.display()
42 );
43 } else {
44 println!(
45 "Entry {} is a file with name \"{}\" ({} bytes)",
46 i,
47 outpath.display(),
48 file.size()
49 );
50 }
51 }
52
53 0
54 }
55