Struct ZipFile

struct ZipFile<'a, R: Read> { ... }

A struct for reading a zip file

Implementations

impl<'a, R: Read> ZipFile<'a, R>

fn version_made_by(self: &Self) -> (u8, u8)

Get the version of the file

fn name(self: &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.

fn name_raw(self: &Self) -> &[u8]

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

The encoding of this data is currently undefined.

fn sanitized_name(self: &Self) -> PathBuf

Get the name of the file in a sanitized form. It truncates the name to the first NULL byte, removes a leading '/' and removes '..' parts.

fn mangled_name(self: &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.

fn enclosed_name(self: &Self) -> Option<PathBuf>

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.

fn comment(self: &Self) -> &str

Get the comment of the file

fn compression(self: &Self) -> CompressionMethod

Get the compression method used to store the file

fn encrypted(self: &Self) -> bool

Get if the files is encrypted or not

fn compressed_size(self: &Self) -> u64

Get the size of the file, in bytes, in the archive

fn size(self: &Self) -> u64

Get the size of the file, in bytes, when uncompressed

fn last_modified(self: &Self) -> Option<DateTime>

Get the time the file was last modified

fn is_dir(self: &Self) -> bool

Returns whether the file is actually a directory

fn is_symlink(self: &Self) -> bool

Returns whether the file is actually a symbolic link

fn is_file(self: &Self) -> bool

Returns whether the file is a normal file (i.e. not a directory or symlink)

fn unix_mode(self: &Self) -> Option<u32>

Get unix mode for the file

fn crc32(self: &Self) -> u32

Get the CRC32 hash of the original file

fn extra_data(self: &Self) -> Option<&[u8]>

Get the extra data of the zip header for this file

fn data_start(self: &Self) -> u64

Get the starting offset of the data of the compressed file

fn header_start(self: &Self) -> u64

Get the starting offset of the zip header for this file

fn central_header_start(self: &Self) -> u64

Get the starting offset of the zip header in the central directory for this file

fn options(self: &Self) -> SimpleFileOptions

Get the SimpleFileOptions that would be used to write this file to a new zip archive.

impl<R: Read> ZipFile<'_, R>

fn extra_data_fields(self: &Self) -> impl Iterator<Item = &ExtraField>

iterate through all extra fields

impl<'a, R> Freeze for ZipFile<'a, R>

impl<'a, R> RefUnwindSafe for ZipFile<'a, R>

impl<'a, R> Send for ZipFile<'a, R>

impl<'a, R> Sync for ZipFile<'a, R>

impl<'a, R> Unpin for ZipFile<'a, R>

impl<'a, R> UnwindSafe for ZipFile<'a, R>

impl<R> LittleEndianReadExt for ZipFile<'a, R>

impl<R: Read> Drop for ZipFile<'_, R>

fn drop(self: &mut Self)

impl<R: Read> HasZipMetadata for ZipFile<'_, R>

fn get_metadata(self: &Self) -> &ZipFileData

impl<R: Read> Read for ZipFile<'_, R>

fn read(self: &mut Self, buf: &mut [u8]) -> io::Result<usize>
fn read_exact(self: &mut Self, buf: &mut [u8]) -> io::Result<()>
fn read_to_end(self: &mut Self, buf: &mut Vec<u8>) -> io::Result<usize>
fn read_to_string(self: &mut Self, buf: &mut String) -> io::Result<usize>

impl<T> Any for ZipFile<'a, R>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ZipFile<'a, R>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for ZipFile<'a, R>

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

impl<T> From for ZipFile<'a, R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Same for ZipFile<'a, R>

impl<T, U> Into for ZipFile<'a, R>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for ZipFile<'a, R>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for ZipFile<'a, R>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>