pub struct ZipFile<'a> { /* private fields */ }
Expand description
A struct for reading a zip file
Implementations§
source§impl<'a> ZipFile<'a>
impl<'a> ZipFile<'a>
Methods for retrieving information on zip files
sourcepub fn version_made_by(&self) -> (u8, u8)
pub fn version_made_by(&self) -> (u8, u8)
Get the version of the file
sourcepub fn name(&self) -> &str
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.
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 sanitized_name(&self) -> PathBuf
👎Deprecated since 0.5.7: by stripping ..
s from the path, the meaning of paths can change.
mangled_name
can be used if this behaviour is desirable
pub fn sanitized_name(&self) -> PathBuf
..
s from the path, the meaning of paths can change.
mangled_name
can be used if this behaviour is desirableGet the name of the file in a sanitized form. It truncates the name to the first NULL byte, removes a leading ‘/’ and removes ‘..’ parts.
sourcepub fn mangled_name(&self) -> PathBuf
pub fn mangled_name(&self) -> PathBuf
Rewrite the path, ignoring any path components with special meaning.
- Absolute paths are made relative
ParentDir
s 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/../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
.
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) -> DateTime
pub fn last_modified(&self) -> DateTime
Get the time the file was last modified
sourcepub fn extra_data(&self) -> Option<&[u8]>
pub fn extra_data(&self) -> Option<&[u8]>
Get the extra data of the zip header for this file
sourcepub fn data_start(&self) -> u64
pub fn data_start(&self) -> u64
Get the starting offset of the data of the compressed file
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 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<'a> Read for ZipFile<'a>
impl<'a> Read for ZipFile<'a>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.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
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> 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 more