[][src]Struct delharc::header::LhaHeader

pub struct LhaHeader {
    pub level: u8,
    pub compression: [u8; 5],
    pub compressed_size: u64,
    pub original_size: u64,
    pub filename: Box<[u8]>,
    pub msdos_attrs: MsDosAttrs,
    pub last_modified: u32,
    pub os_type: u8,
    pub file_crc: u16,
    pub extended_area: Box<[u8]>,
    pub first_header_len: u32,
    pub extra_headers: Box<[u8]>,
}

Semi-parsed LHA header.

Fields

level: u8

Header level: 0, 1, 2 or 3.

compression: [u8; 5]

Raw compression identifier.

compressed_size: u64

Compressed file size.

original_size: u64

Original file size.

filename: Box<[u8]>

A raw filename for level 1 or 0 headers, might be empty. Always being empty for levels 2 or 3.

In this instance the filename is stored in extra headers.

msdos_attrs: MsDosAttrs

MS-DOS attributes.

last_modified: u32

File's last modified date, format depends on the header level.

  • Level 0 and 1 - MS-DOS format (no time zone).
  • Level 2 and 3 - Unix timestamp (UTC).

The "last modified" timestamp can also be found in the extended area and extra headers, as well as other kinds of timestamps (- last access, created).

os_type: u8

A raw OS-TYPE.

file_crc: u16

Uncompressed file's CRC-16.

extended_area: Box<[u8]>

An extended area as raw bytes.

first_header_len: u32

The size of the first extra header.

extra_headers: Box<[u8]>

The extra headers' data.

Implementations

impl LhaHeader[src]

pub fn read<R: Read>(rd: R) -> Result<Option<LhaHeader>>[src]

Attempts to parse the LHA header. Returns Ok(Some(LhaHeader)) on success. Returns Ok(None) if the end of archive marker (a 0 byte) was encountered.

The method validates all length and checksum fields of the header, but does not parse extra headers except:

All extra data is available as raw bytes and extra headers can be iterated with LhaHeader::iter_extra.

Instance methods can be further called on the parsed LhaHeader struct to attempt to parse the name and path of the file or other file's meta-data.

Errors

Returns an error from the underlying reading operations or because a malformed header was encountered.

pub fn iter_extra(&self) -> ExtraHeaderIter

Important traits for ExtraHeaderIter<'a>

impl<'a> Iterator for ExtraHeaderIter<'a> type Item = &'a [u8];
[src]

Returns an iterator that will iterate through extra headers, yielding the headers' raw data, excluding the next header length field.

Note

Each iterated raw header will have at least the size of 1 byte containing the header identifier.

impl LhaHeader[src]

pub fn is_directory(&self) -> bool[src]

Returns true if the archive is an empty directory or a symbolic link.

pub fn parse_os_type(&self) -> Result<OsType, UnrecognizedOsType>[src]

Attempts to parse the os_type field and returns the OsType enum on success.

pub fn parse_last_modified(&self) -> TimestampResult[src]

Attempts to parse the extended area, extra headers and as a last resort the last_modified field taking into account the header level, and on success returns an instance of DateTime<Utc> or a NaiveDateTime wrapped in an TimestampResult enum.

pub fn compression_method(
    &self
) -> Result<CompressionMethod, UnrecognizedCompressionMethod>
[src]

Attempts to parse the compression method field and returns the CompressionMethod enum on success.

pub fn parse_pathname(&self) -> PathBuf[src]

Attempts to parse the filename field and searches the extended data for the directory and an alternative file name and returns a PathBuf.

The routine converts all non-ascii or control ascii characters to %xx sequences and all system specific directory separator characters to _ in file names.

Malicious path components, like .., . or // are stripped from the path names.

Notes

  • If the path name could not be found the returned PathBuf will be empty.
  • Some filesystems may still reject the file or path names if path names include some forbidden characters, e.g. ? or * in Windows.
  • This method makes its best effort to return a non-absolute path name, however it is not guaranteed, so make sure the path is not absolute before creating a file or a directory.

Trait Implementations

impl Clone for LhaHeader[src]

impl Debug for LhaHeader[src]

impl Default for LhaHeader[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.