Library to read Tar archives (by GNU Tar) in no_std contexts with zero allocations. The crate is simple and only supports reading of "basic" archives, therefore no extensions, such as GNU Longname. The maximum supported file size is 100 characters including the NULL-byte. Forked from: https://github.com/phip1611/tar-no-std
Go to file
Philipp Schuster 547429a3dd
Merge pull request #4 from semiviral/main
update bitflags dependency `1.3` -> `2.0`
2023-04-11 10:39:45 +02:00
.github/workflows MSRV fix 2022-05-02 21:59:51 +02:00
examples 'alloc'-feature and owning tar archive type (v0.1.5) 2021-10-11 15:30:24 +02:00
src #[repr(transparent)] for ModeFlags 2023-04-02 06:15:42 -05:00
tests initial commit 2021-10-04 11:13:09 +02:00
.editorconfig CI fix 2022-05-02 21:41:13 +02:00
.gitignore readme fix (v0.1.1) 2021-10-04 11:42:15 +02:00
build.sh 'alloc'-feature and owning tar archive type (v0.1.5) 2021-10-11 15:30:24 +02:00
Cargo.toml undo version bump 2023-04-02 08:27:47 -05:00
README.md MSRV fix 2022-05-02 21:59:51 +02:00

tar-no-std - Parse Tar Archives (Tarballs)

Due to historical reasons, there are several formats of tar archives. All of them are based on the same principles, but have some subtle differences that often make them incompatible with each other. [0]

Library to read Tar archives (by GNU Tar) in no_std contexts with zero allocations. If you have a standard environment and need full feature support, I recommend the use of https://crates.io/crates/tar instead.

Limitations

The crate is simple and only supports reading of "basic" archives, therefore no extensions, such as GNU Longname. The maximum supported file name length is 100 characters including the NULL-byte. The maximum supported file size is 8GiB. Also, directories are not supported yet but only flat collections of files.

Use Case

This library is useful, if you write a kernel or a similar low-level application, which needs "a bunch of files" from an archive ("init ramdisk"). The Tar file could for example come as a Multiboot2 boot module provided by the bootloader.

This crate focuses on extracting files from uncompressed Tar archives created with default options by GNU Tar. GNU Extensions such as sparse files, incremental archives, and long filename extension are not supported yet. This link gives a good overview over possible archive formats and their limitations.

Example (without alloc-feature)

use tar_no_std::TarArchiveRef;

fn main() {
    // log: not mandatory
    std::env::set_var("RUST_LOG", "trace");
    env_logger::init();

    // also works in no_std environment (except the println!, of course)
    let archive = include_bytes!("../tests/gnu_tar_default.tar");
    let archive = TarArchiveRef::new(archive);
    // Vec needs an allocator of course, but the library itself doesn't need one
    let entries = archive.entries().collect::<Vec<_>>();
    println!("{:#?}", entries);
    println!("content of last file:");
    println!("{:#?}", entries[2].data_as_str().expect("Invalid UTF-8") );
}

Alloc Feature

This crate allows the usage of the additional Cargo build time feature alloc. When this is used, the crate also provides the type TarArchive, which owns the data on the heap.

Compression (tar.gz)

If your tar file is compressed, e.g. by .tar.gz/gzip, you need to uncompress the bytes first (e.g. by a gzip library). Afterwards, this crate can read the Tar archive format from the uncompressed bytes.

MSRV

The MSRV is 1.52.1 stable.