Struct ZipFile
pub struct ZipFile<'a, R: Read + ?Sized> { /* private fields */ }
A struct for reading a zip file
When reading from a ZipFile using [Self::read()], keep in mind that read() does not guarantee the buffer will be fully filled in a single call.
If your logic depends on the buffer being completely populated, use [Self::read_exact()] instead. It will continue reading until the entire buffer is filled or an error occurs.
Implementations
impl<'a, R: Read + ?Sized> ZipFile<'a, R>
fn version_made_by(&self) -> (u8, u8)Get the version of the file
fn name(&self) -> &strGet 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_namemethod to validate the name as a safe path.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.
fn sanitized_name(&self) -> PathBufGet 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) -> PathBufRewrite 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/../barasfoo/bar(instead ofbar). Because of this,ZipFile::enclosed_nameis the better option in most scenarios.fn enclosed_name(&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/../baris fine,foo/../../baris 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) -> &strGet the comment of the file
fn compression(&self) -> CompressionMethodGet the compression method used to store the file
fn encrypted(&self) -> boolGet if the files is encrypted or not
fn compressed_size(&self) -> u64Get the size of the file, in bytes, in the archive
fn size(&self) -> u64Get the size of the file, in bytes, when uncompressed
fn last_modified(&self) -> Option<DateTime>Get the time the file was last modified
fn is_dir(&self) -> boolReturns whether the file is actually a directory
fn is_symlink(&self) -> boolReturns whether the file is actually a symbolic link
fn is_file(&self) -> boolReturns whether the file is a normal file (i.e. not a directory or symlink)
fn unix_mode(&self) -> Option<u32>Get unix mode for the file
fn crc32(&self) -> u32Get the CRC32 hash of the original file
fn extra_data(&self) -> Option<&[u8]>Get the extra data of the zip header for this file
fn data_start(&self) -> Option<u64>Get the starting offset of the data of the compressed file
fn header_start(&self) -> u64Get the starting offset of the zip header for this file
fn central_header_start(&self) -> u64Get the starting offset of the zip header in the central directory for this file
fn options(&self) -> SimpleFileOptionsGet the
SimpleFileOptionsthat would be used to write this file to a new zip archive.
impl<R: Read> ZipFile<'_, R>
fn extra_data_fields(&self) -> impl Iterator<Item = &ExtraField>iterate through all extra fields
Trait Implementations
impl<'a, R: Debug + Read + ?Sized> Debug for ZipFile<'a, R>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<R: Read + ?Sized> Drop for ZipFile<'_, R>
fn drop(&mut self)
impl<R: Read + ?Sized> HasZipMetadata for ZipFile<'_, R>
fn get_metadata(&self) -> &ZipFileData
impl<R: Read + ?Sized> Read for ZipFile<'_, R>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
Auto Trait Implementations
impl<'a, R> !Freeze for ZipFile<'a, R>
impl<'a, R> !UnwindSafe for ZipFile<'a, R>
impl<'a, R> RefUnwindSafe for ZipFile<'a, R>
where
ZipFileReader<'a, R>: RefUnwindSafe,
R: ?Sized,
impl<'a, R> Send for ZipFile<'a, R>
where
ZipFileReader<'a, R>: Send,
R: ?Sized,
impl<'a, R> Sync for ZipFile<'a, R>
where
ZipFileReader<'a, R>: Sync,
R: ?Sized,
impl<'a, R> Unpin for ZipFile<'a, R>
where
ZipFileReader<'a, R>: Unpin,
R: ?Sized,
impl<'a, R> UnsafeUnpin for ZipFile<'a, R>
where
ZipFileReader<'a, R>: UnsafeUnpin,
R: ?Sized,
Blanket Implementations
impl<R> LittleEndianReadExt for ZipFile<'a, R>
where
R: Read,
impl<T> Any for ZipFile<'a, R>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for ZipFile<'a, R>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for ZipFile<'a, R>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for ZipFile<'a, R>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Same for ZipFile<'a, R>
type Output = T;
impl<T, U> Into<U> for ZipFile<'a, R>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for ZipFile<'a, R>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for ZipFile<'a, R>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>