pub struct ZipFile<'a, R: Read + ?Sized> { /* private fields */ }Expand description
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§
Source§impl<'a, R: Read + ?Sized> ZipFile<'a, R>
Methods for retrieving information on zip files
impl<'a, R: Read + ?Sized> ZipFile<'a, R>
Methods for retrieving information on zip files
Sourcepub fn name_raw(&self) -> &[u8] ⓘ
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.
Sourcepub fn name(&self) -> ZipResult<Cow<'_, str>>
pub fn name(&self) -> ZipResult<Cow<'_, 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.
Sourcepub fn mangled_name(&self) -> ZipResult<PathBuf>
pub fn mangled_name(&self) -> ZipResult<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.
Sourcepub fn enclosed_name(&self) -> Option<PathBuf>
pub 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.
Sourcepub fn header_start(&self) -> u64
pub fn header_start(&self) -> u64
Get the starting offset of the zip header for this file
Sourcepub fn central_header_start(&self) -> u64
pub fn central_header_start(&self) -> u64
Get the starting offset of the zip header in the central directory for this file
Sourcepub fn version_made_by(&self) -> (u8, u8)
pub fn version_made_by(&self) -> (u8, u8)
Get the version of the file
Sourcepub fn version_needed(&self) -> u16
pub fn version_needed(&self) -> u16
PKZIP version needed to open this file (from APPNOTE 4.4.3.2).
Sourcepub fn external_attributes(&self) -> u32
pub fn external_attributes(&self) -> u32
Get the external attributes of the file
Sourcepub fn flags(&self) -> ZipFileFlags
pub fn flags(&self) -> ZipFileFlags
Get the flags of the file
Sourcepub fn compression(&self) -> CompressionMethod
pub fn compression(&self) -> CompressionMethod
Get the compression method used to store the file
Sourcepub fn compressed_size(&self) -> u64
pub fn compressed_size(&self) -> u64
Get the size of the file, in bytes, in the archive
Sourcepub fn last_modified(&self) -> Option<DateTime>
pub fn last_modified(&self) -> Option<DateTime>
Get the time the file was last modified
Sourcepub fn is_symlink(&self) -> bool
pub fn is_symlink(&self) -> bool
Returns whether the file is actually a symbolic link
Sourcepub fn is_file(&self) -> bool
pub fn is_file(&self) -> bool
Returns whether the file is a normal file (i.e. not a directory or symlink)
Sourcepub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
Returns whether the file is read-only. (On Unix, this means it’s not readable by anyone.)
Sourcepub fn extra_data(&self) -> Option<Vec<u8>>
pub fn extra_data(&self) -> Option<Vec<u8>>
Get the extra data of the zip header for this file
Sourcepub fn data_start(&self) -> Option<u64>
pub fn data_start(&self) -> Option<u64>
Get the starting offset of the data of the compressed file
Sourcepub fn options(&self) -> SimpleFileOptions
pub fn options(&self) -> SimpleFileOptions
Get the SimpleFileOptions that would be used to write this file to
a new zip archive.
Source§impl<R: Read> ZipFile<'_, R>
Methods for retrieving information on zip files
impl<R: Read> ZipFile<'_, R>
Methods for retrieving information on zip files
Sourcepub fn extra_data_fields(&self) -> impl Iterator<Item = &ExtraField>
pub fn extra_data_fields(&self) -> impl Iterator<Item = &ExtraField>
iterate through all extra fields
Trait Implementations§
Source§impl<R: Read + ?Sized> HasZipMetadata for ZipFile<'_, R>
impl<R: Read + ?Sized> HasZipMetadata for ZipFile<'_, R>
Source§fn get_metadata(&self) -> &ZipFileData
fn get_metadata(&self) -> &ZipFileData
Source§impl<R: Read + ?Sized> Read for ZipFile<'_, R>
impl<R: Read + ?Sized> Read for ZipFile<'_, R>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf. Read moreSource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf. Read moreSource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf. Read more1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)Source§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)