ZipSliceArchive

Struct ZipSliceArchive 

Source
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>

Source

pub fn entries(&self) -> ZipSliceEntries<'_>

Returns an iterator over the entries in the central directory of the archive.

Source

pub fn as_bytes(&self) -> &[u8]

Returns the byte slice that represents the zip file.

This will include the entire input slice.

Source

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.

Source

pub fn eocd_offset(&self) -> u64

Returns the offset of the End of Central Directory (EOCD) signature.

See ZipArchive::eocd_offset() for more details.

Source

pub fn directory_offset(&self) -> u64

The declared offset of the start of the central directory.

See ZipArchive::directory_offset() for more details.

Source

pub fn end_offset(&self) -> u64

Returns the offset where the ZIP archive ends.

See ZipArchive::end_offset for more details.

Source

pub fn comment(&self) -> ZipStr<'_>

The comment of the zip file.

Source

pub fn into_reader(self) -> ZipArchive<T>

👎Deprecated: Use ZipSliceArchive::into_zip_archive instead

Converts the ZipSliceArchive into a general ZipArchive.

This is useful for unifying code that might handle both slice-based and reader-based archives.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: Clone + AsRef<[u8]>> Clone for ZipSliceArchive<T>

Source§

fn clone(&self) -> ZipSliceArchive<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + AsRef<[u8]>> Debug for ZipSliceArchive<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ZipSliceArchive<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ZipSliceArchive<T>
where T: RefUnwindSafe,

§

impl<T> Send for ZipSliceArchive<T>
where T: Send,

§

impl<T> Sync for ZipSliceArchive<T>
where T: Sync,

§

impl<T> Unpin for ZipSliceArchive<T>
where T: Unpin,

§

impl<T> UnwindSafe for ZipSliceArchive<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.