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>
impl<'a> ZipFileHeaderRecord<'a>
Sourcepub fn is_dir(&self) -> bool
pub fn is_dir(&self) -> bool
Describes if the file is a directory.
See ZipFilePath::is_dir for more information.
Sourcepub fn has_data_descriptor(&self) -> bool
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
Sourcepub fn wayfinder(&self) -> ZipArchiveEntryWayfinder
pub fn wayfinder(&self) -> ZipArchiveEntryWayfinder
Describes where the file’s data is located within the archive.
Sourcepub fn uncompressed_size_hint(&self) -> u64
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.
Sourcepub fn compressed_size_hint(&self) -> u64
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.
Sourcepub fn local_header_offset(&self) -> u64
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.
Sourcepub fn compression_method(&self) -> CompressionMethod
pub fn compression_method(&self) -> CompressionMethod
The compression method used to compress the data
Sourcepub fn file_path(&self) -> ZipFilePath<RawPath<'a>>
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");
}Sourcepub fn last_modified(&self) -> ZipDateTimeKind
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.
Sourcepub fn mode(&self) -> EntryMode
pub fn mode(&self) -> EntryMode
Returns the file mode information extracted from the external file attributes.
Sourcepub fn crc32(&self) -> u32
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.
Sourcepub fn central_directory_offset(&self) -> u64
pub fn central_directory_offset(&self) -> u64
Returns the offset from the start of reader where this central directory record was parsed from.
Sourcepub fn extra_fields(&self) -> ExtraFields<'_> ⓘ
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>
impl<'a> Clone for ZipFileHeaderRecord<'a>
Source§fn clone(&self) -> ZipFileHeaderRecord<'a>
fn clone(&self) -> ZipFileHeaderRecord<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more