Struct Header
#[repr(C)]
pub struct Header { /* private fields */ }
Representation of the header of an entry in an archive
Implementations
impl Header
fn new_gnu() -> HeaderCreates a new blank GNU header.
The GNU style header is the default for this library and allows various extensions such as long path names, long link names, and setting the atime/ctime metadata attributes of files.
fn new_ustar() -> HeaderCreates a new blank UStar header.
The UStar style header is an extension of the original archive header which enables some extra metadata along with storing a longer (but not too long) path name.
UStar is also the basis used for pax archives.
fn new_old() -> HeaderCreates a new blank old header.
This header format is the original archive header format which all other versions are compatible with (e.g. they are a superset). This header format limits the path name limit and isn't able to contain extra metadata like atime/ctime.
fn as_old(&self) -> &OldHeaderView this archive header as a raw "old" archive header.
This view will always succeed as all archive header formats will fill out at least the fields specified in the old header format.
fn as_old_mut(&mut self) -> &mut OldHeaderSame as
as_old, but the mutable version.fn as_ustar(&self) -> Option<&UstarHeader>View this archive header as a raw UStar archive header.
The UStar format is an extension to the tar archive format which enables longer pathnames and a few extra attributes such as the group and user name.
This cast may not succeed as this function will test whether the magic/version fields of the UStar format have the appropriate values, returning
Noneif they aren't correct.fn as_ustar_mut(&mut self) -> Option<&mut UstarHeader>Same as
as_ustar_mut, but the mutable version.fn as_gnu(&self) -> Option<&GnuHeader>View this archive header as a raw GNU archive header.
The GNU format is an extension to the tar archive format which enables longer pathnames and a few extra attributes such as the group and user name.
This cast may not succeed as this function will test whether the magic/version fields of the GNU format have the appropriate values, returning
Noneif they aren't correct.fn as_gnu_mut(&mut self) -> Option<&mut GnuHeader>Same as
as_gnu, but the mutable version.fn from_byte_slice(bytes: &[u8]) -> &HeaderTreats the given byte slice as a header.
Panics if the length of the passed slice is not equal to 512.
fn as_bytes(&self) -> &[u8; 512]Returns a view into this header as a byte array.
fn as_mut_bytes(&mut self) -> &mut [u8; 512]Returns a view into this header as a byte array.
fn set_metadata(&mut self, meta: &Metadata)Blanket sets the metadata in this header from the metadata argument provided.
This is useful for initializing a
Headerfrom the OS's metadata from a file. By default, this will useHeaderMode::Completeto include all metadata.fn set_metadata_in_mode(&mut self, meta: &Metadata, mode: HeaderMode)Sets only the metadata relevant to the given HeaderMode in this header from the metadata argument provided.
fn entry_size(&self) -> Result<u64>Returns the size of entry's data this header represents.
This is different from
Header::sizefor sparse files, which have some longersize()but shorterentry_size(). Theentry_size()listed here should be the number of bytes in the archive this header describes.May return an error if the field is corrupted.
fn size(&self) -> Result<u64>Returns the file size this header represents.
May return an error if the field is corrupted.
fn set_size(&mut self, size: u64)Encodes the
sizeargument into the size field of this header.fn path(&self) -> Result<Cow<'_, Path>>Returns the raw path name stored in this header.
This method may fail if the pathname is not valid Unicode and this is called on a Windows platform.
Note that this function will convert any
\characters to directory separators.fn path_bytes(&self) -> Cow<'_, [u8]>Returns the pathname stored in this header as a byte array.
This function is guaranteed to succeed, but you may wish to call the
pathmethod to convert to aPath.Note that this function will convert any
\characters to directory separators.fn set_path<P: AsRef<Path>>(&mut self, p: P) -> Result<()>Sets the path name for this header.
This function will set the pathname listed in this header, encoding it in the appropriate format. May fail if the path is too long or if the path specified is not Unicode and this is a Windows platform. Will strip out any "." path component, which signifies the current directory.
Note: This function does not support names over 100 bytes, or paths over 255 bytes, even for formats that support longer names. Instead, use
Buildermethods to insert a long-name extension at the same time as the file content.fn set_path_absolute<P: AsRef<Path>>(&mut self, p: P) -> Result<()>Sets the path name for this header.
Same as set_path but allows abosolut paths
fn link_name(&self) -> Result<Option<Cow<'_, Path>>>Returns the link name stored in this header, if any is found.
This method may fail if the pathname is not valid Unicode and this is called on a Windows platform.
Ok(None)being returned, however, indicates that the link name was not present.Note that this function will convert any
\characters to directory separators.fn link_name_bytes(&self) -> Option<Cow<'_, [u8]>>Returns the link name stored in this header as a byte array, if any.
This function is guaranteed to succeed, but you may wish to call the
link_namemethod to convert to aPath.Note that this function will convert any
\characters to directory separators.fn set_link_name<P: AsRef<Path>>(&mut self, p: P) -> Result<()>Sets the link name for this header.
This function will set the linkname listed in this header, encoding it in the appropriate format. May fail if the link name is too long or if the path specified is not Unicode and this is a Windows platform. Will strip out any "." path component, which signifies the current directory.
To use GNU long link names, prefer instead
crate::Builder::append_link.fn set_link_name_literal<P: AsRef<[u8]>>(&mut self, p: P) -> Result<()>Sets the link name for this header without any transformation.
This function is like
Self::set_link_namebut accepts an arbitrary byte array. Hence it will not perform any canonicalization, such as replacing duplicate//with/.fn mode(&self) -> Result<u32>Returns the mode bits for this file
May return an error if the field is corrupted.
fn set_mode(&mut self, mode: u32)Encodes the
modeprovided into this header.fn uid(&self) -> Result<u64>Returns the value of the owner's user ID field
May return an error if the field is corrupted.
fn set_uid(&mut self, uid: u64)Encodes the
uidprovided into this header.fn gid(&self) -> Result<u64>Returns the value of the group's user ID field
fn set_gid(&mut self, gid: u64)Encodes the
gidprovided into this header.fn mtime(&self) -> Result<u64>Returns the last modification time in Unix time format
fn set_mtime(&mut self, mtime: u64)Encodes the
mtimeprovided into this header.Note that this time is typically a number of seconds passed since January 1, 1970.
fn username(&self) -> Result<Option<&str>, Utf8Error>Return the user name of the owner of this file.
A return value of
Ok(Some(..))indicates that the user name was present and was valid utf-8,Ok(None)indicates that the user name is not present in this archive format, andErrindicates that the user name was present but was not valid utf-8.fn username_bytes(&self) -> Option<&[u8]>Returns the user name of the owner of this file, if present.
A return value of
Noneindicates that the user name is not present in this header format.fn set_username(&mut self, name: &str) -> Result<()>Sets the username inside this header.
This function will return an error if this header format cannot encode a user name or the name is too long.
fn groupname(&self) -> Result<Option<&str>, Utf8Error>Return the group name of the owner of this file.
A return value of
Ok(Some(..))indicates that the group name was present and was valid utf-8,Ok(None)indicates that the group name is not present in this archive format, andErrindicates that the group name was present but was not valid utf-8.fn groupname_bytes(&self) -> Option<&[u8]>Returns the group name of the owner of this file, if present.
A return value of
Noneindicates that the group name is not present in this header format.fn set_groupname(&mut self, name: &str) -> Result<()>Sets the group name inside this header.
This function will return an error if this header format cannot encode a group name or the name is too long.
fn device_major(&self) -> Result<Option<u32>>Returns the device major number, if present.
This field may not be present in all archives, and it may not be correctly formed in all archives.
Ok(Some(..))means it was present and correctly decoded,Ok(None)indicates that this header format does not include the device major number, andErrindicates that it was present and failed to decode.fn set_device_major(&mut self, major: u32) -> Result<()>Encodes the value
majorinto the dev_major field of this header.This function will return an error if this header format cannot encode a major device number.
fn device_minor(&self) -> Result<Option<u32>>Returns the device minor number, if present.
This field may not be present in all archives, and it may not be correctly formed in all archives.
Ok(Some(..))means it was present and correctly decoded,Ok(None)indicates that this header format does not include the device minor number, andErrindicates that it was present and failed to decode.fn set_device_minor(&mut self, minor: u32) -> Result<()>Encodes the value
minorinto the dev_minor field of this header.This function will return an error if this header format cannot encode a minor device number.
fn entry_type(&self) -> EntryTypeReturns the type of file described by this header.
fn set_entry_type(&mut self, ty: EntryType)Sets the type of file that will be described by this header.
fn cksum(&self) -> Result<u32>Returns the checksum field of this header.
May return an error if the field is corrupted.
fn set_cksum(&mut self)Sets the checksum field of this header based on the current fields in this header.
Trait Implementations
impl Clone for Header
fn clone(&self) -> Header
impl Debug for Header
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl Freeze for Header
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnsafeUnpin for Header
impl UnwindSafe for Header
Blanket Implementations
impl<T> Any for Header
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Header
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Header
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Header
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Header
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Header
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Header
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Header
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Header
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>