Skip to main content

Module archive

Module archive 

Source
Expand description

Read and write pkgsrc binary packages.

pkgsrc binary packages come in two formats:

  1. Unsigned packages: Compressed tar archives (.tgz, .tbz, etc.) containing package metadata (+CONTENTS, +COMMENT, +DESC, etc.) and the package files.

  2. Signed packages: ar(1) archives containing:

    • +PKG_HASH: Hash metadata for verification
    • +PKG_GPG_SIGNATURE: GPG signature of the hash file
    • The original compressed tarball

This module provides a two-layer API:

§Low-level (tar-style streaming)

  • Archive: Streaming access to archive entries
  • Builder: Create new archives by appending entries

§High-level (convenience)

§Examples

§Fast metadata reading

use pkgsrc::archive::BinaryPackage;

let pkg = BinaryPackage::open("package-1.0.tgz")?;
println!("Package: {}", pkg.pkgname().unwrap_or("unknown"));
println!("Comment: {}", pkg.metadata().comment());

// Convert to summary for repository management
let summary = pkg.to_summary()?;

§Installing a package (iterating entries)

use pkgsrc::archive::BinaryPackage;

let pkg = BinaryPackage::open("package-1.0.tgz")?;

// Check dependencies first (fast, uses cached metadata)
for dep in pkg.plist().depends() {
    println!("Depends: {}", dep);
}

// Extract files (re-reads archive)
pkg.extract_to("/usr/pkg")?;

§Building a new package

use pkgsrc::archive::Builder;

// Auto-detect compression from filename
let mut builder = Builder::create("package-1.0.tgz")?;
builder.append_metadata_file("+COMMENT", b"A test package")?;
builder.append_file("bin/hello", b"#!/bin/sh\necho hello", 0o755)?;
builder.finish()?;

§Signing an existing package

use pkgsrc::archive::BinaryPackage;

let pkg = BinaryPackage::open("package-1.0.tgz")?;
let signature = b"GPG SIGNATURE DATA";
pkg.sign(signature)?.write_to("package-1.0-signed.tgz")?;

Structs§

Archive
Low-level streaming access to package archives.
BinaryPackage
A pkgsrc binary package with cached metadata.
Builder
Build a new compressed package archive.
ChecksumFailure
A single failure reported by BinaryPackage::verify_checksums.
ExtractOptions
Options for extracting package files.
ExtractedFile
Result of extracting a single file.
Members
Iterator over a package’s leading metadata members.
MetadataMember
A single metadata member yielded by Members.
MetadataReader
Streaming reader for a binary package’s leading metadata members.
PkgHash
The +PKG_HASH file contents for signed packages.
SignedArchive
A signed binary package ready to be written.
SummaryOptions
Options for converting a BinaryPackage to a Summary.

Enums§

ArchiveError
Error type for archive operations.
ArchiveType
Type of binary package archive.
ChecksumFailureKind
Reason a file failed checksum verification.
Compression
Compression format for package archives.
PkgHashAlgorithm
Hash algorithm used for package signing.

Constants§

DEFAULT_BLOCK_SIZE
Default block size for package hashing (64KB).
PKGSRC_SIGNATURE_VERSION
Current pkgsrc signature version.

Type Aliases§

Result
Result type for archive operations.