Yi Kong | f19c3f2 | 2021-02-13 04:04:00 +0800 | [diff] [blame] | 1 | use std::io::{self, Read}; |
| 2 | |
| 3 | fn main() { |
| 4 | std::process::exit(real_main()); |
| 5 | } |
| 6 | |
| 7 | fn 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 Stoep | 486ff5a | 2023-02-17 09:53:43 +0100 | [diff] [blame] | 23 | Err(e) => println!("Could not read the file: {e:?}"), |
Yi Kong | f19c3f2 | 2021-02-13 04:04:00 +0800 | [diff] [blame] | 24 | }; |
| 25 | } |
| 26 | Ok(None) => break, |
| 27 | Err(e) => { |
Jeff Vander Stoep | 486ff5a | 2023-02-17 09:53:43 +0100 | [diff] [blame] | 28 | println!("Error encountered while reading zip: {e:?}"); |
Yi Kong | f19c3f2 | 2021-02-13 04:04:00 +0800 | [diff] [blame] | 29 | return 1; |
| 30 | } |
| 31 | } |
| 32 | } |
David LeGare | 132eccb | 2022-04-11 16:44:12 +0000 | [diff] [blame] | 33 | |
| 34 | 0 |
Yi Kong | f19c3f2 | 2021-02-13 04:04:00 +0800 | [diff] [blame] | 35 | } |