Add contains_file_named

This commit is contained in:
Chris Hennick 2024-04-20 11:58:18 -07:00
parent e4d0a0228a
commit 16b66841b3
No known key found for this signature in database
GPG key ID: DA47AABA4961C509
5 changed files with 20 additions and 7 deletions

View file

@ -267,4 +267,11 @@
### Changed ### Changed
- Eliminated a custom `AtomicU64` type by replacing it with `OnceLock` in the only place it's used. - Eliminated a custom `AtomicU64` type by replacing it with `OnceLock` in the only place it's used.
- `FileOptions` now has the subtype `SimpleFileOptions` which implements `Copy` but has no extra data. - `FileOptions` now has the subtype `SimpleFileOptions` which implements `Copy` but has no extra data.
## [1.1.1]
### Added
- `contains_file_named`: check whether a file entry exists in a zip file, without initializing the
metadata or needing to mutably borrow the `ZipArchive`.

View file

@ -1,6 +1,6 @@
[package] [package]
name = "zip" name = "zip"
version = "1.1.0" version = "1.1.1"
authors = [ authors = [
"Mathijs van de Nes <git@mathijs.vd-nes.nl>", "Mathijs van de Nes <git@mathijs.vd-nes.nl>",
"Marli Frost <marli@frost.red>", "Marli Frost <marli@frost.red>",

View file

@ -4,7 +4,7 @@ zip
[![Build Status](https://github.com/Pr0methean/zip-next/actions/workflows/ci.yaml/badge.svg)](https://github.com/Pr0methean/zip-next/actions?query=branch%3Amaster+workflow%3ACI) [![Build Status](https://github.com/Pr0methean/zip-next/actions/workflows/ci.yaml/badge.svg)](https://github.com/Pr0methean/zip-next/actions?query=branch%3Amaster+workflow%3ACI)
[![Crates.io version](https://img.shields.io/crates/v/zip.svg)](https://crates.io/crates/zip) [![Crates.io version](https://img.shields.io/crates/v/zip.svg)](https://crates.io/crates/zip)
[Documentation](https://docs.rs/zip/1.1.0/zip/) [Documentation](https://docs.rs/zip/latest/zip/)
Info Info
---- ----
@ -33,14 +33,14 @@ With all default features:
```toml ```toml
[dependencies] [dependencies]
zip = "1.1.0" zip = "1.1.1"
``` ```
Without the default features: Without the default features:
```toml ```toml
[dependencies] [dependencies]
zip = { version = "1.1.0", default-features = false } zip = { version = "1.1.1", default-features = false }
``` ```
The features available are: The features available are:
@ -53,7 +53,8 @@ The features available are:
This is the fastest `deflate` implementation available. This is the fastest `deflate` implementation available.
* `deflate-zopfli`: Enables deflating files with the `zopfli` library (used when compression quality is 10..=264). This * `deflate-zopfli`: Enables deflating files with the `zopfli` library (used when compression quality is 10..=264). This
is the most effective `deflate` implementation available. is the most effective `deflate` implementation available.
* `deflate64`: Enables the deflate64 compression algorithm. Decompression is only supported. * `deflate64`: Enables the deflate64 compression algorithm. Only decompression is supported.
* `lzma`: Enables the LZMA compression algorithm. Only decompression is supported.
* `bzip2`: Enables the BZip2 compression algorithm. * `bzip2`: Enables the BZip2 compression algorithm.
* `time`: Enables features using the [time](https://github.com/rust-lang-deprecated/time) crate. * `time`: Enables features using the [time](https://github.com/rust-lang-deprecated/time) crate.
* `chrono`: Enables converting last-modified `zip::DateTime` to and from `chrono::NaiveDateTime`. * `chrono`: Enables converting last-modified `zip::DateTime` to and from `chrono::NaiveDateTime`.

View file

@ -53,6 +53,6 @@ mod zipcrypto;
/// ///
/// ```toml /// ```toml
/// [dependencies] /// [dependencies]
/// zip = "=1.1.0" /// zip = "=1.1.1"
/// ``` /// ```
pub mod unstable; pub mod unstable;

View file

@ -650,6 +650,11 @@ impl<R: Read + Seek> ZipArchive<R> {
pub fn by_name(&mut self, name: &str) -> ZipResult<ZipFile> { pub fn by_name(&mut self, name: &str) -> ZipResult<ZipFile> {
self.by_name_with_optional_password(name, None) self.by_name_with_optional_password(name, None)
} }
/// Check for a file entry, but do not decrypt it or initialize metadata.
pub fn contains_file_named(&self, name: &str) -> bool {
self.shared.names_map.contains_key(name)
}
fn by_name_with_optional_password<'a>( fn by_name_with_optional_password<'a>(
&'a mut self, &'a mut self,