pub struct PackageReader<R: Read + Seek> { /* private fields */ }Expand description
A package-specialized ZIP reader that is optimized for reading all file names as fast as possible. This reader only accesses file immutably. This reader ignores folders.
If the underlying stream (such as file) is modified while this reader is create, subsequent file reads are really likely to error (will never panic!).
Implementations§
Source§impl<R: Read + Seek> PackageReader<R>
impl<R: Read + Seek> PackageReader<R>
Sourcepub fn new(reader: R) -> Result<Self>
pub fn new(reader: R) -> Result<Self>
Create a package reader with the underlying read+seek implementor.
Sourcepub fn clone_with<NewR: Read + Seek>(&self, reader: NewR) -> PackageReader<NewR>
pub fn clone_with<NewR: Read + Seek>(&self, reader: NewR) -> PackageReader<NewR>
A fast clone of this package reader into a new fully independent reader, this will reuse the file list of the current reader. The caller must ensure that this reader points to the same data as the current reader, if not the case, file informations may be wrong and subsequent file reads are likely to return error, this will never panic and not cause any UB!
Sourcepub fn names(&self) -> impl Iterator<Item = &str> + '_
pub fn names(&self) -> impl Iterator<Item = &str> + '_
Return an iterator over all file names in the package. The position of file names
in this iterator is the same that can be used when reading from index, using
the Self::read_by_index() method.
pub fn index_by_name(&self, file_name: &str) -> Option<usize>
Sourcepub fn read_by_name(
&mut self,
file_name: &str,
) -> Result<PackageFileReader<&mut R>>
pub fn read_by_name( &mut self, file_name: &str, ) -> Result<PackageFileReader<&mut R>>
Open a package file by its name and return a borrowed reader if successful.
Sourcepub fn read_by_index(
&mut self,
file_index: usize,
) -> Result<PackageFileReader<&mut R>>
pub fn read_by_index( &mut self, file_index: usize, ) -> Result<PackageFileReader<&mut R>>
Open a package file by its index and return a borrowed reader if successful.
Note that the returned reader has no buffered over the original reader given at construction, you should handle buffering if necessary.