Skip to main content

Crate tar_core

Crate tar_core 

Source
Expand description

Sans-IO tar parsing for sync and async runtimes.

tar-core provides zero-copy parsing and building of tar archives that works with any I/O model. The parse::Parser has no trait bounds on readers—it just processes byte slices. This enables code sharing between sync crates like tar-rs and async crates like tokio-tar.

All header structs use the zerocopy crate for safe, efficient memory-mapped access without allocations. Supports POSIX.1-1988, UStar (POSIX.1-2001), and GNU tar formats.

§Header Formats

Tar archives have evolved through several formats:

  • Old (POSIX.1-1988): The original Unix tar format with basic fields
  • UStar (POSIX.1-2001): Adds magic/version, user/group names, and path prefix
  • GNU tar: Extends UStar with sparse file support and long name/link extensions

§Example

use tar_core::{Header, EntryType};

// Parse a header from raw bytes
let data = [0u8; 512]; // Would normally come from a tar file
let header = Header::from_bytes(&data);

// Access header fields
let entry_type = header.entry_type();
let path = header.path_bytes();

§Parsing

For parsing complete tar archives with automatic handling of GNU and PAX extensions, see the sans-IO parse module. It also contains security parse::Limits and the parse::ParseError type.

Re-exports§

pub use builder::blocks_for_size;
pub use builder::EntryBuilder;
pub use builder::ExtensionMode;
pub use builder::HeaderBuilder;
pub use builder::PaxBuilder;
pub use builder::LINKNAME_MAX_LEN;
pub use builder::NAME_MAX_LEN;

Modules§

builder
Builder pattern for creating tar headers.
parse
Sans-IO tar archive parser.

Structs§

GnuExtSparseHeader
Extended sparse header block for GNU tar.
GnuHeader
GNU tar header format with sparse file support.
GnuSparseHeader
GNU tar sparse file chunk descriptor.
Header
High-level tar header wrapper with accessor methods.
OldHeader
Old-style (POSIX.1-1988) tar header with named fields.
PaxExtension
A single PAX extended header key/value pair.
PaxExtensions
Iterator over PAX extended header records.
SparseEntry
A decoded sparse file data region.
UstarHeader
UStar (POSIX.1-2001) tar header format.

Enums§

EntryType
Tar entry type indicating the kind of file system object.
HeaderError
Errors that can occur when parsing or building tar headers.
PaxError
Error parsing a PAX extension record.

Constants§

GNU_MAGIC
Magic string for GNU tar format headers (“ustar “).
GNU_VERSION
Version field for GNU tar format headers (“ \0“).
HEADER_SIZE
Size of a tar header block in bytes.
PAX_ATIME
PAX extended header key for access time.
PAX_CTIME
PAX extended header key for change time.
PAX_GID
PAX extended header key for owner group ID.
PAX_GNAME
PAX extended header key for owner group name.
PAX_GNU_SPARSE
PAX extended header prefix for GNU sparse file extensions.
PAX_GNU_SPARSE_MAJOR
PAX key for GNU sparse file format major version.
PAX_GNU_SPARSE_MAP
PAX key for GNU sparse file map.
PAX_GNU_SPARSE_MINOR
PAX key for GNU sparse file format minor version.
PAX_GNU_SPARSE_NAME
PAX key for GNU sparse file name.
PAX_GNU_SPARSE_NUMBLOCKS
PAX key for GNU sparse file number of blocks.
PAX_GNU_SPARSE_NUMBYTES
PAX key for GNU sparse file numbytes.
PAX_GNU_SPARSE_OFFSET
PAX key for GNU sparse file offset.
PAX_GNU_SPARSE_REALSIZE
PAX key for GNU sparse file real size.
PAX_GNU_SPARSE_SIZE
PAX key for GNU sparse file size.
PAX_LINKPATH
PAX extended header key for the link target path.
PAX_MTIME
PAX extended header key for modification time.
PAX_PATH
PAX extended header key for the file path.
PAX_SCHILY_XATTR
PAX extended header prefix for SCHILY extended attributes.
PAX_SIZE
PAX extended header key for file size.
PAX_UID
PAX extended header key for owner user ID.
PAX_UNAME
PAX extended header key for owner user name.
USTAR_MAGIC
Magic string for UStar format headers (“ustar\0”).
USTAR_VERSION
Version field for UStar format headers (“00”).

Type Aliases§

Result
Result type for header parsing operations.