pub struct ZipSliceArchive<T: AsRef<[u8]>> { /* private fields */ }Expand description
Represents a Zip archive that operates on an in-memory data.
A ZipSliceArchive is more efficient and easier to use than a ZipArchive,
as there is no buffer management and memory copying involved.
§Examples
use rawzip::{ZipArchive, ZipSliceArchive, Error};
fn process_zip_slice(data: &[u8]) -> Result<(), Error> {
let archive = ZipArchive::from_slice(data)?;
println!("Found {} entries.", archive.entries_hint());
for entry_result in archive.entries() {
let entry = entry_result?;
println!("File: {}", entry.file_path().try_normalize()?.as_ref());
}
Ok(())
}Implementations§
Source§impl<T: AsRef<[u8]>> ZipSliceArchive<T>
impl<T: AsRef<[u8]>> ZipSliceArchive<T>
Sourcepub fn entries(&self) -> ZipSliceEntries<'_> ⓘ
pub fn entries(&self) -> ZipSliceEntries<'_> ⓘ
Returns an iterator over the entries in the central directory of the archive.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the byte slice that represents the zip file.
This will include the entire input slice.
Sourcepub fn entries_hint(&self) -> u64
pub fn entries_hint(&self) -> u64
Returns a hint for the total number of entries in the archive.
This value is read from the End of Central Directory record.
Sourcepub fn eocd_offset(&self) -> u64
pub fn eocd_offset(&self) -> u64
Returns the offset of the End of Central Directory (EOCD) signature.
See ZipArchive::eocd_offset() for more details.
Sourcepub fn directory_offset(&self) -> u64
pub fn directory_offset(&self) -> u64
The declared offset of the start of the central directory.
See ZipArchive::directory_offset() for more details.
Sourcepub fn end_offset(&self) -> u64
pub fn end_offset(&self) -> u64
Returns the offset where the ZIP archive ends.
See ZipArchive::end_offset for more details.
Sourcepub fn into_reader(self) -> ZipArchive<T>
👎Deprecated: Use ZipSliceArchive::into_zip_archive instead
pub fn into_reader(self) -> ZipArchive<T>
ZipSliceArchive::into_zip_archive insteadConverts the ZipSliceArchive into a general ZipArchive.
This is useful for unifying code that might handle both slice-based and reader-based archives.
Sourcepub fn into_zip_archive(self) -> ZipArchive<Cursor<T>>
pub fn into_zip_archive(self) -> ZipArchive<Cursor<T>>
Converts the ZipSliceArchive into a general ZipArchive.
This is useful for unifying code that might handle both slice-based and
reader-based archives. The data is wrapped in a std::io::Cursor to
provide the ReaderAt implementation needed for ZipArchive.
Sourcepub fn get_entry(
&self,
entry: ZipArchiveEntryWayfinder,
) -> Result<ZipSliceEntry<'_>, Error>
pub fn get_entry( &self, entry: ZipArchiveEntryWayfinder, ) -> Result<ZipSliceEntry<'_>, Error>
Seeks to the given file entry in the zip archive.
See ZipArchive::get_entry for more details. The biggest difference
between the reader and slice APIs is that the slice APIs will eagerly
validate that the entire compressed data is present.