pub struct BinaryPackage { /* private fields */ }Expand description
A pkgsrc binary package with cached metadata.
This provides fast access to package metadata without re-reading the
archive. The metadata is read once during BinaryPackage::open, and subsequent
operations like BinaryPackage::archive or BinaryPackage::extract_to re-open
the archive as needed.
§Example
use pkgsrc::archive::BinaryPackage;
// Fast metadata access
let pkg = BinaryPackage::open("package-1.0.tgz").unwrap();
println!("Name: {}", pkg.pkgname().unwrap_or("unknown"));
println!("Comment: {}", pkg.metadata().comment());
// Generate summary for repository
let summary = pkg.to_summary().unwrap();
// Extract files (re-reads archive)
pkg.extract_to("/usr/pkg").unwrap();Implementations§
Source§impl BinaryPackage
impl BinaryPackage
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Open a package from a file path.
This reads only the metadata entries at the start of the archive, providing fast access to package information without decompressing the entire file.
Sourcepub fn compression(&self) -> Compression
pub fn compression(&self) -> Compression
Return the compression format.
Sourcepub fn archive_type(&self) -> ArchiveType
pub fn archive_type(&self) -> ArchiveType
Return the archive type (signed or unsigned).
Sourcepub fn build_info(&self) -> &HashMap<String, Vec<String>>
pub fn build_info(&self) -> &HashMap<String, Vec<String>>
Return the build info key-value pairs.
Sourcepub fn build_info_value(&self, key: &str) -> Option<&str>
pub fn build_info_value(&self, key: &str) -> Option<&str>
Get a specific build info value (first value if multiple exist).
Sourcepub fn build_info_values(&self, key: &str) -> Option<&[String]>
pub fn build_info_values(&self, key: &str) -> Option<&[String]>
Get all values for a build info key.
Sourcepub fn gpg_signature(&self) -> Option<&[u8]>
pub fn gpg_signature(&self) -> Option<&[u8]>
Return the GPG signature (for signed packages).
Sourcepub fn archive(&self) -> Result<Archive<BufReader<File>>>
pub fn archive(&self) -> Result<Archive<BufReader<File>>>
Open the archive for iteration (re-reads the file).
Sourcepub fn extract_to(&self, dest: impl AsRef<Path>) -> Result<()>
pub fn extract_to(&self, dest: impl AsRef<Path>) -> Result<()>
Extract all files to a destination directory.
This re-reads the archive and extracts all entries.
Sourcepub fn extract_with_plist(
&self,
dest: impl AsRef<Path>,
options: ExtractOptions,
) -> Result<Vec<ExtractedFile>>
pub fn extract_with_plist( &self, dest: impl AsRef<Path>, options: ExtractOptions, ) -> Result<Vec<ExtractedFile>>
Extract files to a destination directory with plist-based permissions.
This method extracts files and applies permissions specified in the
packing list (@mode, @owner, @group directives).
§Arguments
dest- Destination directory for extractionoptions- Extraction options controlling mode/ownership application
§Returns
A vector of ExtractedFile describing each extracted file.
§Example
use pkgsrc::archive::{BinaryPackage, ExtractOptions};
let pkg = BinaryPackage::open("package-1.0.tgz").unwrap();
let options = ExtractOptions::new().with_mode();
let extracted = pkg.extract_with_plist("/usr/pkg", options).unwrap();
for file in &extracted {
println!("Extracted: {}", file.path.display());
}Sourcepub fn verify_checksums(
&self,
dest: impl AsRef<Path>,
) -> Result<Vec<(PathBuf, String, String)>>
pub fn verify_checksums( &self, dest: impl AsRef<Path>, ) -> Result<Vec<(PathBuf, String, String)>>
Verify checksums of extracted files against plist MD5 values.
This method checks that files in the destination directory match the MD5 checksums recorded in the packing list.
§Arguments
dest- Directory where files were extracted
§Returns
A vector of tuples containing (file_path, expected_hash, actual_hash) for files that failed verification. Empty vector means all passed.
Sourcepub fn sign(&self, signature: &[u8]) -> Result<SignedArchive>
pub fn sign(&self, signature: &[u8]) -> Result<SignedArchive>
Sign this package.
Re-reads the package file to compute hashes and create a signed archive.
Sourcepub fn to_summary(&self) -> Result<Summary>
pub fn to_summary(&self) -> Result<Summary>
Convert this package to a Summary entry.
This uses default options (no file checksum computation).
Use to_summary_with_opts for more control.