]> git.proxmox.com Git - rustc.git/blame - vendor/zip/examples/stdin_info.rs
New upstream version 1.69.0+dfsg1
[rustc.git] / vendor / zip / examples / stdin_info.rs
CommitLineData
9c376795
FG
1use 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]),
9ffffee4 23 Err(e) => println!("Could not read the file: {e:?}"),
9c376795
FG
24 };
25 }
26 Ok(None) => break,
27 Err(e) => {
9ffffee4 28 println!("Error encountered while reading zip: {e:?}");
9c376795
FG
29 return 1;
30 }
31 }
32 }
33
34 0
35}