From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/zip/examples/extract_lorem.rs | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 third_party/rust/zip/examples/extract_lorem.rs (limited to 'third_party/rust/zip/examples/extract_lorem.rs') diff --git a/third_party/rust/zip/examples/extract_lorem.rs b/third_party/rust/zip/examples/extract_lorem.rs new file mode 100644 index 0000000000..bc50abe164 --- /dev/null +++ b/third_party/rust/zip/examples/extract_lorem.rs @@ -0,0 +1,31 @@ +use std::io::prelude::*; + +fn main() { + std::process::exit(real_main()); +} + +fn real_main() -> i32 { + let args: Vec<_> = std::env::args().collect(); + if args.len() < 2 { + println!("Usage: {} ", args[0]); + return 1; + } + let fname = std::path::Path::new(&*args[1]); + let zipfile = std::fs::File::open(fname).unwrap(); + + let mut archive = zip::ZipArchive::new(zipfile).unwrap(); + + let mut file = match archive.by_name("test/lorem_ipsum.txt") { + Ok(file) => file, + Err(..) => { + println!("File test/lorem_ipsum.txt not found"); + return 2; + } + }; + + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap(); + println!("{contents}"); + + 0 +} -- cgit v1.2.3