pkg-extractor 0.1.0

Extract macOS .pkg files (flat packages) — supports product and component packages, PBZX payloads, and xar fallback
Documentation
// Copyright (C) 2026 Thibault Saunier <tsaunier@igalia.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use env_logger::Env;
use log::debug;
use std::{fs::File, io::BufReader, path::PathBuf};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[structopt(name = "pkg-extractor", about = "Extract macOS .pkg files")]
struct Opt {
    #[structopt(parse(from_os_str))]
    pkg_path: PathBuf,

    #[structopt(short = "o", long = "output", parse(from_os_str))]
    output_dir: Option<PathBuf>,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize logger
    let env = Env::default().filter_or(
        "RUST_LOG",
        if std::env::args().any(|arg| arg == "--debug") {
            "debug"
        } else {
            "info"
        },
    );

    env_logger::init_from_env(env);

    // Parse command line arguments
    let opt = Opt::from_args();

    // Create and run extractor
    debug!("Opening package file: {}", opt.pkg_path.display());
    let file = File::open(&opt.pkg_path)?;
    let reader = BufReader::new(file);

    pkg_extractor::PkgExtractor::new_with_file_path(reader, opt.output_dir, opt.pkg_path).extract()
}