Skip to main content

HeaderBuilder

Struct HeaderBuilder 

Source
pub struct HeaderBuilder { /* private fields */ }
Expand description

Builder for creating tar headers.

This provides a fluent API for constructing tar headers with proper field formatting and checksum calculation.

§Example

use tar_core::builder::HeaderBuilder;
use tar_core::EntryType;

let mut builder = HeaderBuilder::new_ustar();
builder
    .path(b"example.txt").unwrap()
    .mode(0o644).unwrap()
    .uid(1000).unwrap()
    .gid(1000).unwrap()
    .size(0).unwrap()
    .mtime(1234567890).unwrap()
    .entry_type(EntryType::Regular);

let header = builder.finish();

Implementations§

Source§

impl HeaderBuilder

Source

pub fn new_ustar() -> Self

Create a new builder for a UStar format header.

Source

pub fn new_gnu() -> Self

Create a new builder for a GNU tar format header.

Source

pub fn path(&mut self, path: impl AsRef<[u8]>) -> Result<&mut Self>

Set the file path (name field, 100 bytes).

§Errors

Returns an error if the path is longer than 100 bytes.

Source

pub fn mode(&mut self, mode: u32) -> Result<&mut Self>

Set the file mode.

§Errors

Returns HeaderError::FieldOverflow if the mode exceeds the 8-byte octal capacity (max 0o7777777 = 2,097,151).

Source

pub fn uid(&mut self, uid: u64) -> Result<&mut Self>

Set the owner user ID.

Format-aware: GNU headers use base-256 for values exceeding the octal range; ustar headers use octal only.

§Errors

Returns HeaderError::FieldOverflow if the value cannot be represented in the header format.

Source

pub fn gid(&mut self, gid: u64) -> Result<&mut Self>

Set the owner group ID.

Format-aware: GNU headers use base-256 for values exceeding the octal range; ustar headers use octal only.

§Errors

Returns HeaderError::FieldOverflow if the value cannot be represented in the header format.

Source

pub fn size(&mut self, size: u64) -> Result<&mut Self>

Set the file size.

Format-aware: GNU headers use base-256 for values exceeding the octal range; ustar headers use octal only.

§Errors

Returns HeaderError::FieldOverflow if the value cannot be represented in the header format.

Source

pub fn mtime(&mut self, mtime: u64) -> Result<&mut Self>

Set the modification time as a Unix timestamp.

Format-aware: GNU headers use base-256 for values exceeding the octal range; ustar headers use octal only.

§Errors

Returns HeaderError::FieldOverflow if the value cannot be represented in the header format.

Source

pub fn entry_type(&mut self, entry_type: EntryType) -> &mut Self

Set the entry type.

Set the link name for symbolic/hard links (100 bytes).

§Errors

Returns an error if the link name is longer than 100 bytes.

Source

pub fn username(&mut self, name: impl AsRef<[u8]>) -> Result<&mut Self>

Set the owner user name (32 bytes, UStar/GNU only).

§Errors

Returns an error if the username is longer than 32 bytes.

Source

pub fn groupname(&mut self, name: impl AsRef<[u8]>) -> Result<&mut Self>

Set the owner group name (32 bytes, UStar/GNU only).

§Errors

Returns an error if the group name is longer than 32 bytes.

Source

pub fn device(&mut self, major: u32, minor: u32) -> Result<&mut Self>

Set device major and minor numbers.

Used for character and block device entries.

§Errors

Returns HeaderError::FieldOverflow if the values don’t fit in the 8-byte octal fields (max 0o7777777 = 2,097,151).

Source

pub fn prefix(&mut self, prefix: impl AsRef<[u8]>) -> Result<&mut Self>

Set the UStar prefix field for long paths (155 bytes).

§Errors

Returns an error if the prefix is longer than 155 bytes.

Source

pub fn as_header(&self) -> &Header

Get a reference to the current header for inspection.

Note: The checksum field will not be valid until finish is called.

Source

pub fn as_header_mut(&mut self) -> &mut Header

Get a mutable reference to the raw header.

This is intended for direct field manipulation that the builder doesn’t expose (e.g. GNU sparse header fields).

Source

pub fn finish(&mut self) -> Header

Compute the checksum and return the final header.

This fills in the checksum field and returns the complete 512-byte header.

Trait Implementations§

Source§

impl Clone for HeaderBuilder

Source§

fn clone(&self) -> HeaderBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HeaderBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HeaderBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.