]> git.proxmox.com Git - cargo.git/blob - vendor/tar-0.4.14/examples/extract_file.rs
New upstream version 0.24.0
[cargo.git] / vendor / tar-0.4.14 / examples / extract_file.rs
1 //! An example of extracting a file in an archive.
2 //!
3 //! Takes a tarball on standard input, looks for an entry with a listed file
4 //! name as the first argument provided, and then prints the contents of that
5 //! file to stdout.
6
7 extern crate tar;
8
9 use std::io::{stdin, stdout, copy};
10 use std::env::args_os;
11 use std::path::Path;
12
13 use tar::Archive;
14
15 fn main() {
16 let first_arg = args_os().skip(1).next().unwrap();
17 let filename = Path::new(&first_arg);
18 let mut ar = Archive::new(stdin());
19 for file in ar.entries().unwrap() {
20 let mut f = file.unwrap();
21 if f.path().unwrap() == filename {
22 copy(&mut f, &mut stdout()).unwrap();
23 }
24 }
25 }