zip-rs / zip-old

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

Read only a file in the zip file without decompressing it #328

Closed cn-hew closed 1 year ago

cn-hew commented 1 year ago

hi~, How do I get the file name without a path in a zip? Is there a way to do this? Can I directly read the matching file in the subdirectory based on the file name without caring which directory it is in?

Plecra commented 1 year ago

You can inspect the files that you find in an archive with ZipArchive::file_names. You can implement any searching algorithm you like through that.

Here, it looks like you might use rs let file_name = ...; for entry in archive.file_names() { if entry.ends_with(file_name) { // handle the archive.by_name(entry) } }

cn-hew commented 1 year ago

You can inspect the files that you find in an archive with ZipArchive::file_names. You can implement any searching algorithm you like through that.

Here, it looks like you might use rs let file_name = ...; for entry in archive.file_names() { if entry.ends_with(file_name) { // handle the archive.by_name(entry) } }

thanks bro i used your method it really works I'm not familiar with rust