zip-rs / zip-old

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

Add a function to check file name exists, without iterator over all names by file_names() #438

Closed zangloo closed 6 months ago

zangloo commented 7 months ago

I'm writing a program, that need to check a lot of referenced files exists in the zip file without open it. If the zip containt a lot of files, the check will take a lot of time. I found the file_names() is collect the names of a map, so maybe add a funciton like pub fn file_exists(name: &str) will be much faster then iterate all file names.

Pr0methean commented 6 months ago

You can use by_name(name) != Err(ZipError::FileNotFound).

zangloo commented 6 months ago

I just want check if the file is exists, if using by_name() and the file exists, it will create a reader, do seek, read header, calc the size, etc... . And i may check a file list existance for every file, then by using by_name, will cause a lot of useless operations.

Pr0methean commented 6 months ago

A new method index_for_name will release in version 1.1.1, with no side effects and taking an immutable borrow; then you'll be able to use index_for_name(name).is_some().

zangloo commented 6 months ago

That's great. Thanks.