Skip to main content

ZipFileHeaderRecord

Struct ZipFileHeaderRecord 

Source
pub struct ZipFileHeaderRecord<'a> { /* private fields */ }
Expand description

Represents a record from the Zip archive’s central directory for a single file

This contains metadata about the file. If interested in navigating to the file contents, use [ZipFileHeaderRecord::wayfinder].

Reference 4.3.12 in the zip specification

Implementations§

Source§

impl<'a> ZipFileHeaderRecord<'a>

Source

pub fn is_dir(&self) -> bool

Describes if the file is a directory.

See ZipFilePath::is_dir for more information.

Source

pub fn has_data_descriptor(&self) -> bool

Returns true if the entry has a data descriptor that follows its compressed data.

From the spec (4.3.9.1):

This descriptor MUST exist if bit 3 of the general purpose bit flag is set

Source

pub fn wayfinder(&self) -> ZipArchiveEntryWayfinder

Describes where the file’s data is located within the archive.

Source

pub fn uncompressed_size_hint(&self) -> u64

The purported number of bytes of the uncompressed data.

WARNING: this number has not yet been validated, so don’t trust it to make allocation decisions.

Source

pub fn compressed_size_hint(&self) -> u64

The purported number of bytes of the compressed data.

WARNING: this number has not yet been validated, so don’t trust it to make allocation decisions.

Source

pub fn local_header_offset(&self) -> u64

The declared offset to the local file header within the Zip archive.

To verify the validity of this offset, call ZipSliceArchive::get_entry or ZipArchive::get_entry.

The minimum of all local header offsets (or directory_offset() when a zip is empty), will be the length of prelude data in a zip archive (data that is unrelated to the zip archive).

See RangeReader for an example.

Source

pub fn compression_method(&self) -> CompressionMethod

The compression method used to compress the data

Source

pub fn file_path(&self) -> ZipFilePath<RawPath<'a>>

Returns the file path in its raw form.

§Safety

The raw path may contain unsafe components like:

  • Absolute paths (/etc/passwd)
  • Directory traversal (../../../etc/passwd)
  • Invalid UTF-8 sequences
§Example
// Get raw path (potentially unsafe)
let raw_path = entry.file_path();

// Convert to safe path
let safe_path = raw_path.try_normalize()?;
println!("Safe path: {}", safe_path.as_ref());

// Check if it's a directory
if safe_path.is_dir() {
    println!("This is a directory");
}
Source

pub fn last_modified(&self) -> ZipDateTimeKind

Returns the last modification date and time.

This method parses the extra field data to locate more accurate timestamps.

Source

pub fn mode(&self) -> EntryMode

Returns the file mode information extracted from the external file attributes.

Source

pub fn crc32(&self) -> u32

The declared CRC32 checksum of the uncompressed data.

To verify the validity of this value, ZipEntry::verifying_reader will return an error if when the decompressed data does not match this checksum.

Source

pub fn central_directory_offset(&self) -> u64

Returns the offset from the start of reader where this central directory record was parsed from.

Source

pub fn extra_fields(&self) -> ExtraFields<'_>

Returns an iterator over the extra fields in this file header record.

Extra fields contain additional metadata about files in ZIP archives, such as timestamps, alignment information, and platform-specific data.

§Examples
let archive = ZipArchive::from_slice(data)?;
for entry_result in archive.entries() {
    let entry = entry_result?;
    let mut extra_fields = entry.extra_fields();
    for (field_id, field_data) in extra_fields.by_ref() {
        match field_id {
            ExtraFieldId::JAVA_JAR => {
                println!("Handle jar CAFE field with {} bytes", field_data.len());
            }
            _ => {
                println!("Found extra field ID: 0x{:04x}", field_id.as_u16());
            }
        }
    }

    // If desired, check for truncated data
    if !extra_fields.remaining_bytes().is_empty() {
        println!("Warning: Some extra field data was truncated");
    }
}

Raw access to the entire extra field data is available when remaining_bytes is called prior to any iteration.

Trait Implementations§

Source§

impl<'a> Clone for ZipFileHeaderRecord<'a>

Source§

fn clone(&self) -> ZipFileHeaderRecord<'a>

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<'a> Debug for ZipFileHeaderRecord<'a>

Source§

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

Formats the value using the given formatter. 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.