pub struct ZipStreamFileMetadata(_);
Expand description

Additional metadata for the file.

Implementations§

source§

impl ZipStreamFileMetadata

source

pub fn name(&self) -> &str

Get the name of the file

Warnings

It is dangerous to use this name directly when extracting an archive. It may contain an absolute path (/etc/shadow), or break out of the current directory (../runtime). Carelessly writing to these paths allows an attacker to craft a ZIP archive that will overwrite critical files.

You can use the ZipFile::enclosed_name method to validate the name as a safe path.

source

pub fn name_raw(&self) -> &[u8]

Get the name of the file, in the raw (internal) byte representation.

The encoding of this data is currently undefined.

source

pub fn mangled_name(&self) -> PathBuf

Rewrite the path, ignoring any path components with special meaning.

  • Absolute paths are made relative
  • ParentDirs are ignored
  • Truncates the filename at a NULL byte

This is appropriate if you need to be able to extract something from any archive, but will easily misrepresent trivial paths like foo/../bar as foo/bar (instead of bar). Because of this, ZipFile::enclosed_name is the better option in most scenarios.

source

pub fn enclosed_name(&self) -> Option<&Path>

Ensure the file path is safe to use as a Path.

  • It can’t contain NULL bytes
  • It can’t resolve to a path outside the current directory

    foo/../bar is fine, foo/../../bar is not.

  • It can’t be an absolute path

This will read well-formed ZIP files correctly, and is resistant to path-based exploits. It is recommended over ZipFile::mangled_name.

source

pub fn is_dir(&self) -> bool

Returns whether the file is actually a directory

source

pub fn is_file(&self) -> bool

Returns whether the file is a regular file

source

pub fn comment(&self) -> &str

Get the comment of the file

source

pub fn data_start(&self) -> u64

Get the starting offset of the data of the compressed file

source

pub fn unix_mode(&self) -> Option<u32>

Get unix mode for the file

Trait Implementations§

source§

impl Debug for ZipStreamFileMetadata

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.