Merge commit 'fec26926a8' as 'tokio-tar'

This commit is contained in:
Thomas Eizinger 2021-02-25 11:20:47 +11:00
commit 18ba8f49c4
34 changed files with 6427 additions and 0 deletions

View file

@ -0,0 +1,28 @@
//! 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 tokio_tar as async_tar;
use std::{env::args_os, path::Path};
use tokio::io::{copy, stdin, stdout};
use tokio_stream::*;
use async_tar::Archive;
fn main() {
tokio::runtime::Runtime::new().unwrap().block_on(async {
let first_arg = args_os().nth(1).unwrap();
let filename = Path::new(&first_arg);
let mut ar = Archive::new(stdin());
let mut entries = ar.entries().unwrap();
while let Some(file) = entries.next().await {
let mut f = file.unwrap();
if f.path().unwrap() == filename {
copy(&mut f, &mut stdout()).await.unwrap();
}
}
});
}

View file

@ -0,0 +1,21 @@
//! 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 tokio_tar as async_tar;
use tokio::io::stdin;
use tokio_stream::*;
use async_tar::Archive;
fn main() {
tokio::runtime::Runtime::new().unwrap().block_on(async {
let mut ar = Archive::new(stdin());
let mut entries = ar.entries().unwrap();
while let Some(file) = entries.next().await {
let f = file.unwrap();
println!("{}", f.path().unwrap().display());
}
});
}

View file

@ -0,0 +1,54 @@
//! An example of listing raw entries in an archive.
//!
//! Takes a tarball on stdin and prints out all of the entries inside.
extern crate tokio_tar as async_tar;
use tokio::io::stdin;
use tokio_stream::*;
use async_tar::Archive;
fn main() {
tokio::runtime::Runtime::new().unwrap().block_on(async {
let mut ar = Archive::new(stdin());
let mut i = 0;
let mut entries = ar.entries_raw().unwrap();
while let Some(file) = entries.next().await {
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().await {
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())
);
}
}
i += 1;
}
});
}

View file

@ -0,0 +1,16 @@
extern crate tokio_tar as async_tar;
use async_tar::Builder;
use tokio::fs::File;
fn main() {
tokio::runtime::Runtime::new().unwrap().block_on(async {
let file = File::create("foo.tar").await.unwrap();
let mut a = Builder::new(file);
a.append_path("README.md").await.unwrap();
a.append_file("lib.rs", &mut File::open("src/lib.rs").await.unwrap())
.await
.unwrap();
});
}