pub struct ZipLocator { /* private fields */ }Expand description
Locates the End of Central Directory (EOCD) record in a ZIP archive.
The ZipLocator is responsible for finding the EOCD record, which is crucial
for reading the contents of a ZIP file.
Implementations§
Source§impl ZipLocator
impl ZipLocator
Sourcepub fn max_search_space(self, max_search_space: u64) -> Self
pub fn max_search_space(self, max_search_space: u64) -> Self
Sets the maximum number of bytes to search for the EOCD signature.
The search is performed backwards from the end of the data source.
use rawzip::ZipLocator;
let locator = ZipLocator::new().max_search_space(1024 * 64); // 64 KiBSourcepub fn locate_in_slice<T: AsRef<[u8]>>(
&self,
data: T,
) -> Result<ZipSliceArchive<T>, (T, Error)>
pub fn locate_in_slice<T: AsRef<[u8]>>( &self, data: T, ) -> Result<ZipSliceArchive<T>, (T, Error)>
Locates the EOCD record within a byte slice.
On success, returns a ZipSliceArchive which allows reading the archive
directly from the slice. On failure, returns the original slice and an Error.
§Examples
use rawzip::ZipLocator;
use std::fs;
use std::io::Read;
let mut file = fs::File::open("assets/readme.zip")?;
let mut data = Vec::new();
file.read_to_end(&mut data)?;
let locator = ZipLocator::new();
match locator.locate_in_slice(&data) {
Ok(archive) => {
println!("Found EOCD in slice, archive has {} files.", archive.entries_hint());
}
Err((_data, e)) => {
eprintln!("Failed to locate EOCD in slice: {:?}", e);
}
}Sourcepub fn locate_in_file(
&self,
file: File,
buffer: &mut [u8],
) -> Result<ZipArchive<FileReader>, (File, Error)>
pub fn locate_in_file( &self, file: File, buffer: &mut [u8], ) -> Result<ZipArchive<FileReader>, (File, Error)>
Locates the EOCD record within a file.
A mutable byte slice to use for reading data from the file. The buffer should be large enough to hold the EOCD record and potentially parts of the ZIP64 EOCD locator if present. A common size might be a few kilobytes.
On failure, returns the original file and an Error.
§Examples
use rawzip::ZipLocator;
use std::fs::File;
let file = File::open("assets/readme.zip")?;
let mut buffer = vec![0; 1024 * 4]; // 4 KiB buffer
let locator = ZipLocator::new();
match locator.locate_in_file(file, &mut buffer) {
Ok(archive) => {
println!("Found EOCD in file, archive has {} files.", archive.entries_hint());
}
Err((_file, e)) => {
eprintln!("Failed to locate EOCD in file: {:?}", e);
}
}Sourcepub fn locate_in_reader<R>(
&self,
reader: R,
buffer: &mut [u8],
) -> Result<ZipArchive<R>, (R, Error)>
pub fn locate_in_reader<R>( &self, reader: R, buffer: &mut [u8], ) -> Result<ZipArchive<R>, (R, Error)>
Locates the EOCD record in a reader that implements positioned io and can seek (for determining length of data).