[go: nahoru, domu]

blob: a609916a09994ea67c04837c33f4719f0a493eb1 [file] [log] [blame]
Yi Kongf19c3f22021-02-13 04:04:00 +08001use std::io::{self, Read};
2
3fn main() {
4 std::process::exit(real_main());
5}
6
7fn real_main() -> i32 {
8 let stdin = io::stdin();
9 let mut stdin_handle = stdin.lock();
10 let mut buf = [0u8; 16];
11
12 loop {
13 match zip::read::read_zipfile_from_stream(&mut stdin_handle) {
14 Ok(Some(mut file)) => {
15 println!(
16 "{}: {} bytes ({} bytes packed)",
17 file.name(),
18 file.size(),
19 file.compressed_size()
20 );
21 match file.read(&mut buf) {
22 Ok(n) => println!("The first {} bytes are: {:?}", n, &buf[0..n]),
Jeff Vander Stoep486ff5a2023-02-17 09:53:43 +010023 Err(e) => println!("Could not read the file: {e:?}"),
Yi Kongf19c3f22021-02-13 04:04:00 +080024 };
25 }
26 Ok(None) => break,
27 Err(e) => {
Jeff Vander Stoep486ff5a2023-02-17 09:53:43 +010028 println!("Error encountered while reading zip: {e:?}");
Yi Kongf19c3f22021-02-13 04:04:00 +080029 return 1;
30 }
31 }
32 }
David LeGare132eccb2022-04-11 16:44:12 +000033
34 0
Yi Kongf19c3f22021-02-13 04:04:00 +080035}