summaryrefslogtreecommitdiffstats
path: root/vendor/zip/examples/extract_lorem.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/zip/examples/extract_lorem.rs')
-rw-r--r--vendor/zip/examples/extract_lorem.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/zip/examples/extract_lorem.rs b/vendor/zip/examples/extract_lorem.rs
new file mode 100644
index 000000000..a34a04f43
--- /dev/null
+++ b/vendor/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: {} <filename>", 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
+}