zip-rs / zip-old

Zip implementation in Rust
MIT License
731 stars 204 forks source link

Add by_name_seek() for Stored zips #369

Closed exFalso closed 5 months ago

exFalso commented 1 year ago

This PR adds a ZipArchive::by_name_seek function which returns a ZipFileSeek structure that implements Seek. This only works for Stored types of zips for now, although I'm sure this can be implemented for compressed archives as well using some kind of lazy indexing structure that helps map compressed indexes to uncompressed ones quickly.

I tried various ways of adding this feature, but I could only make it work like this. I "forked" the ZipFile structure, added a ZipFileSeek, and added a common trait that implements the metadata goodies. The reason I couldn't make it work with a unified approach is because the current library supports non-Seek base readers, and there's no such thing as a dynamic cast in Rust (nor would I want there to be).

One consequence of the trait is that this change became API breaking, as the trait must be imported to access the metadata functions. I can add back the original functions that dispatches to the trait in case this is an issue.

Although I have not added tests to this crate, it has been tested fairly thoroughly with tests testing our own usage of the feature.

exFalso commented 1 year ago

Linking with issue https://github.com/zip-rs/zip/issues/223

Pr0methean commented 5 months ago

Replaced with https://github.com/zip-rs/zip2/pull/69.