1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Archive query methods.
//!
//! This module provides methods for querying archive information, entries,
//! and metadata without extraction.
use std::io::{Read, Seek};
use std::path::PathBuf;
use super::{Archive, ArchiveInfo, Entry};
impl<R: Read + Seek> Archive<R> {
/// Returns information about the archive.
pub fn info(&self) -> &ArchiveInfo {
&self.info
}
/// Returns all entries in the archive.
pub fn entries(&self) -> &[Entry] {
&self.entries
}
/// Returns the archive comment, if any.
///
/// Archive comments are optional metadata stored in the archive header.
/// They are typically used for descriptions or notes about the archive contents.
pub fn comment(&self) -> Option<&str> {
self.header
.files_info
.as_ref()
.and_then(|fi| fi.comment.as_deref())
}
/// Returns the number of entries in the archive.
pub fn len(&self) -> usize {
self.entries.len()
}
/// Returns true if the archive has no entries.
pub fn is_empty(&self) -> bool {
self.entries.is_empty()
}
/// Finds an entry by path.
pub fn entry(&self, path: &str) -> Option<&Entry> {
self.entries.iter().find(|e| e.path.as_str() == path)
}
/// Returns whether this is a multi-volume archive.
pub fn is_multivolume(&self) -> bool {
self.volume_info.is_some()
}
/// Returns the number of volumes in a multi-volume archive.
///
/// Returns `None` for single-file archives.
pub fn volume_count(&self) -> Option<u32> {
self.volume_info.as_ref().map(|v| v.count)
}
/// Returns the paths to all volume files.
///
/// Returns `None` for single-file archives.
pub fn volume_paths(&self) -> Option<&[PathBuf]> {
self.volume_info.as_ref().map(|v| v.paths.as_slice())
}
}