tar (0.4.45)
Published 2026-03-26 11:04:06 +00:00 by siennathesane
Installation
[registry]
default = "gitea"
[registries.gitea]
index = "sparse+ " # Sparse index
# index = " " # Git
[net]
git-fetch-with-cli = truecargo add tar@0.4.45About this package
A Rust implementation of a TAR file reader and writer. This library does not
currently handle compression, but it is abstract over all I/O readers and
writers. Additionally, great lengths are taken to ensure that the entire
contents are never required to be entirely resident in memory all at once.
tar-rs
A tar archive reading/writing library for Rust.
# Cargo.toml
[dependencies]
tar = "0.4"
Reading an archive
extern crate tar;
use std::io::prelude::*;
use std::fs::File;
use tar::Archive;
fn main() {
let file = File::open("foo.tar").unwrap();
let mut a = Archive::new(file);
for file in a.entries().unwrap() {
// Make sure there wasn't an I/O error
let mut file = file.unwrap();
// Inspect metadata about the file
println!("{:?}", file.header().path().unwrap());
println!("{}", file.header().size().unwrap());
// files implement the Read trait
let mut s = String::new();
file.read_to_string(&mut s).unwrap();
println!("{}", s);
}
}
Writing an archive
extern crate tar;
use std::io::prelude::*;
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("file1.txt").unwrap();
a.append_file("file2.txt", &mut File::open("file3.txt").unwrap()).unwrap();
}
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies
| ID | Version |
|---|---|
| filetime | ^0.2.8 |
| astral-tokio-tar | ^0.5 |
| rand | ^0.8 |
| tempfile | ^3 |
| tokio | ^1 |
| tokio-stream | ^0.1 |
| libc | ^0.2 |
| xattr | ^1.1.3 |
Keywords
tar
tarfile
encoding
Details
2026-03-26 11:04:06 +00:00
Assets (1)
Versions (1)
View all
Cargo
0
Alex Crichton <alex@alexcrichton.com>
MIT OR Apache-2.0
65 KiB
tar-0.4.45.crate
65 KiB
0.4.45
2026-03-26