zipatch-rs 1.7.0

Parser for FFXIV ZiPatch patch files
Documentation
//! `apply_patch_file` one-shot wrapper — moved from `src/lib.rs` inline tests
//! during the API-overhaul pass.

use zipatch_rs::test_utils::{MAGIC, make_chunk};
use zipatch_rs::{ApplyError, ParseError, apply_patch_file};

#[test]
fn apply_patch_file_one_shot_creates_directory_on_install_root() {
    // Build a minimal patch on disk (MAGIC + ADIR("oneshot") + EOF_),
    // call the convenience wrapper, and verify the install_root contents.
    let mut adir_body = Vec::new();
    adir_body.extend_from_slice(&7u32.to_be_bytes());
    adir_body.extend_from_slice(b"oneshot");

    let mut patch = Vec::new();
    patch.extend_from_slice(&MAGIC);
    patch.extend_from_slice(&make_chunk(b"ADIR", &adir_body));
    patch.extend_from_slice(&make_chunk(b"EOF_", &[]));

    let tmp = tempfile::tempdir().unwrap();
    let patch_path = tmp.path().join("oneshot.patch");
    std::fs::write(&patch_path, &patch).unwrap();
    let install_root = tmp.path().join("install");
    std::fs::create_dir(&install_root).unwrap();

    apply_patch_file(&patch_path, &install_root).expect("one-shot apply must succeed");

    assert!(
        install_root.join("oneshot").is_dir(),
        "apply_patch_file must have created the directory under install_root"
    );
}

#[test]
fn apply_patch_file_surfaces_parse_failure_as_apply_error_parse() {
    // Missing patch file: open_patch returns ParseError::Io, which the
    // wrapper must surface as ApplyError::Parse(_).
    let tmp = tempfile::tempdir().unwrap();
    let missing = tmp.path().join("does_not_exist.patch");
    let install_root = tmp.path();

    let err = apply_patch_file(&missing, install_root).unwrap_err();
    assert!(
        matches!(err, ApplyError::Parse(ParseError::Io { .. })),
        "missing patch file must surface as ApplyError::Parse(ParseError::Io), got {err:?}"
    );
}