A library to asynchronously read and write TAR archives in Rust.
Tario supports the ustar TAR format. It focuses on efficiently abstracting TAR I/O rather than being a general purpose utility to make all kinds of TAR archives. If that's not what you need, there's tar-rs that you should check out.
Tario is:
- Minimal: Tario only does a few things, but well.
- Lightweight: Tario has minimal dependencies, is conservative on resources, makes no uneccessary copies and performs no allocations at runtime.
- Fast: Tario adds minimal overhead while working with archives.
Using Cargo:
$ cargo add tario
Or manually by editing your project's Cargo.toml:
[dependencies]
tario = 0.1
Tario currently has the following feature switches:
streams
: support for Streams. Enabled by default.
Tario builds on Tokio's async read and write traits but is otherwise not using anything at all from it.
use tokio::io::{AsyncWrite, AsyncWriteExt};
use tario::{Archive, Header};
let mut io: Vec<u8> = Vec::new();
let mut archive = Archive::new(&mut io);
let mut files = [
// Assume a single entry for this example.
("hello.txt", "hello world!"),
];
for (path, contents) in files {
let mut header = Header::new_ustar();
header.set_path(path)?;
header.set_size(contents.len() as u64);
header.set_cksum();
let mut entry = archive.add_entry(header).await?;
entry.write(contents.as_bytes()).await?;
}
archive.finish().await?;
use std::io;
use tokio::io::{AsyncRead, AsyncReadExt};
use tario::Archive;
let io = io::Cursor::new(&[]); // Get a reader from somewhere
let mut archive = Archive::new(io);
let buf = &mut [0u8; 100];
while let Some(mut entry) = archive.next_entry().await? {
loop {
let bytes_written = entry.read(buf).await?;
if bytes_written == 0 {
// Reached entry EOF
break;
}
// do_something_with_buffer(&buf[..bytes_written]);
}
}
This project is licensed under the MIT license.