Expand description
A ZIP reader which acts over a non-seekable source.
API Design
As opposed to other readers provided by this crate, it’s important that the data of an entry is fully read before the proceeding entry is read. This is as a result of not being able to seek forwards or backwards, so we must end up at the start of the next entry.
We encode this invariant within Rust’s type system so that it can be enforced at compile time.
This requires that any transition methods between these encoded types consume the reader and provide a new owned reader back. This is certainly something to keep in mind when working with this reader, but idiomatic code can still be produced nevertheless.
Considerations
As the central directory of a ZIP archive is stored at the end of it, a non-seekable reader doesn’t have access to it. We have to rely on information provided within the local file header which may not be accurate or complete. This results in:
- The inability to read internally stored ZIP archives when using the Stored compression method.
- No file comment being available (defaults to an empty string).
- No internal or external file attributes being available (defaults to 0).
- The extra field data potentially being inconsistent with what’s stored in the central directory.
- None of the following being available when the entry was written with a data descriptor (defaults to 0):
- CRC
- compressed size
- uncompressed size
Example
let mut zip = ZipFileReader::new(Cursor::new([0; 0]));
// Print the name of every file in a ZIP archive.
while let Some(entry) = zip.next_with_entry().await? {
println!("File: {}", entry.reader().entry().filename().as_str().unwrap());
zip = entry.skip().await?;
}Structs
- A type which encodes that
ZipFileReaderis currently reading an entry. - A type which encodes that
ZipFileReaderis ready to open a new entry. - A ZIP reader which acts over a non-seekable source.