diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/tar/examples | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/tar/examples')
-rw-r--r-- | vendor/tar/examples/extract_file.rs | 25 | ||||
-rw-r--r-- | vendor/tar/examples/list.rs | 17 | ||||
-rw-r--r-- | vendor/tar/examples/raw_list.rs | 48 | ||||
-rw-r--r-- | vendor/tar/examples/write.rs | 13 |
4 files changed, 103 insertions, 0 deletions
diff --git a/vendor/tar/examples/extract_file.rs b/vendor/tar/examples/extract_file.rs new file mode 100644 index 000000000..425e9a350 --- /dev/null +++ b/vendor/tar/examples/extract_file.rs @@ -0,0 +1,25 @@ +//! An example of extracting a file in an archive. +//! +//! Takes a tarball on standard input, looks for an entry with a listed file +//! name as the first argument provided, and then prints the contents of that +//! file to stdout. + +extern crate tar; + +use std::env::args_os; +use std::io::{copy, stdin, stdout}; +use std::path::Path; + +use tar::Archive; + +fn main() { + let first_arg = args_os().skip(1).next().unwrap(); + let filename = Path::new(&first_arg); + let mut ar = Archive::new(stdin()); + for file in ar.entries().unwrap() { + let mut f = file.unwrap(); + if f.path().unwrap() == filename { + copy(&mut f, &mut stdout()).unwrap(); + } + } +} diff --git a/vendor/tar/examples/list.rs b/vendor/tar/examples/list.rs new file mode 100644 index 000000000..e2d58daf6 --- /dev/null +++ b/vendor/tar/examples/list.rs @@ -0,0 +1,17 @@ +//! An example of listing the file names of entries in an archive. +//! +//! Takes a tarball on stdin and prints out all of the entries inside. + +extern crate tar; + +use std::io::stdin; + +use tar::Archive; + +fn main() { + let mut ar = Archive::new(stdin()); + for file in ar.entries().unwrap() { + let f = file.unwrap(); + println!("{}", f.path().unwrap().display()); + } +} diff --git a/vendor/tar/examples/raw_list.rs b/vendor/tar/examples/raw_list.rs new file mode 100644 index 000000000..9b86da229 --- /dev/null +++ b/vendor/tar/examples/raw_list.rs @@ -0,0 +1,48 @@ +//! An example of listing raw entries in an archive. +//! +//! Takes a tarball on stdin and prints out all of the entries inside. + +extern crate tar; + +use std::io::stdin; + +use tar::Archive; + +fn main() { + let mut ar = Archive::new(stdin()); + for (i, file) in ar.entries().unwrap().raw(true).enumerate() { + println!("-------------------------- Entry {}", i); + let mut f = file.unwrap(); + println!("path: {}", f.path().unwrap().display()); + println!("size: {}", f.header().size().unwrap()); + println!("entry size: {}", f.header().entry_size().unwrap()); + println!("link name: {:?}", f.link_name().unwrap()); + println!("file type: {:#x}", f.header().entry_type().as_byte()); + println!("mode: {:#o}", f.header().mode().unwrap()); + println!("uid: {}", f.header().uid().unwrap()); + println!("gid: {}", f.header().gid().unwrap()); + println!("mtime: {}", f.header().mtime().unwrap()); + println!("username: {:?}", f.header().username().unwrap()); + println!("groupname: {:?}", f.header().groupname().unwrap()); + + if f.header().as_ustar().is_some() { + println!("kind: UStar"); + } else if f.header().as_gnu().is_some() { + println!("kind: GNU"); + } else { + println!("kind: normal"); + } + + if let Ok(Some(extensions)) = f.pax_extensions() { + println!("pax extensions:"); + for e in extensions { + let e = e.unwrap(); + println!( + "\t{:?} = {:?}", + String::from_utf8_lossy(e.key_bytes()), + String::from_utf8_lossy(e.value_bytes()) + ); + } + } + } +} diff --git a/vendor/tar/examples/write.rs b/vendor/tar/examples/write.rs new file mode 100644 index 000000000..167263d97 --- /dev/null +++ b/vendor/tar/examples/write.rs @@ -0,0 +1,13 @@ +extern crate tar; + +use std::fs::File; +use tar::Builder; + +fn main() { + let file = File::create("foo.tar").unwrap(); + let mut a = Builder::new(file); + + a.append_path("README.md").unwrap(); + a.append_file("lib.rs", &mut File::open("src/lib.rs").unwrap()) + .unwrap(); +} |