Skip to content

Commit 32b46d6

Browse files
committed
bugfix(map): fix parent compression map reading
1 parent 2290cf2 commit 32b46d6

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chd-rs/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ mod tests {
216216
f_out.write_all(&buf).expect("did not write")
217217
}
218218

219+
#[test]
220+
fn read_parent_test() {
221+
let mut p = BufReader::new(File::open(".testimages/TombRaider.chd").expect(""));
222+
let pchd = Chd::open(p, None).expect("parent");
223+
224+
let mut f = BufReader::new(File::open(".testimages/TombRaiderR1.chd").expect(""));
225+
226+
let chd = Chd::open(f, Some(Box::new(pchd))).expect("child");
227+
}
228+
219229
#[test]
220230
#[cfg(feature = "unsound_owning_iterators")]
221231
fn hunk_iter_test() {

chd-rs/src/map.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ fn read_map_v5<F: Read + Seek>(
572572
last_parent = off;
573573
}
574574
CompressionTypeV5::CompressionParent1 => {
575-
last_parent += (header.hunk_bytes / header.unit_bytes) as u64
575+
last_parent += (header.hunk_bytes / header.unit_bytes) as u64;
576+
map_slice[0] = CompressionTypeV5::CompressionParent as u8;
577+
off = last_parent;
576578
}
577579
CompressionTypeV5::CompressionParent0 => {
578580
map_slice[0] = CompressionTypeV5::CompressionParent as u8;

rchdman/src/main.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ enum Commands {
6666
/// input file name
6767
#[clap(short, long, parse(try_from_os_str = validate_file_exists))]
6868
input: PathBuf,
69+
/// parent file name for input CHD
70+
#[clap(short = 'p', long, parse(try_from_os_str = validate_file_exists))]
71+
inputparent: Option<PathBuf>,
6972
},
7073
/// Verifies the integrity of a CHD
7174
Verify {
@@ -452,12 +455,20 @@ fn info(input: &PathBuf, verbose: bool) -> anyhow::Result<()> {
452455
Ok(())
453456
}
454457

455-
fn benchmark(p: impl AsRef<Path>) -> anyhow::Result<()> {
458+
fn benchmark(p: impl AsRef<Path>, ip: Option<impl AsRef<Path>>) -> anyhow::Result<()> {
456459
println!("\nchd-rs - rchdman benchmark");
457-
let mut f = BufReader::new(File::open(p)?);
460+
let f = BufReader::new(File::open(p)?);
461+
let ipf = ip.map(|ip| BufReader::new(File::open(ip).unwrap()));
458462

459463
let start = Instant::now();
460-
let mut chd = Chd::open(&mut f, None)?;
464+
let ipchd = ipf.map(|ipf| Chd::open(ipf, None));
465+
466+
let mut chd = if let Some(ip) = ipchd {
467+
Chd::open(f, Some(Box::new(ip?)))?
468+
} else {
469+
Chd::open(f, None)?
470+
};
471+
461472
let mut hunk_buf = chd.get_hunksized_buffer();
462473
let mut cmp_buf = Vec::new();
463474
let hunk_iter = chd.hunks();
@@ -615,7 +626,7 @@ fn main() -> anyhow::Result<()> {
615626
let cli = Cli::parse();
616627
match &cli.command {
617628
Commands::Info { input, verbose } => info(input, *verbose)?,
618-
Commands::Benchmark { input } => benchmark(input)?,
629+
Commands::Benchmark { input, inputparent } => benchmark(input, inputparent.as_ref())?,
619630
Commands::Verify { input, inputparent } => verify(input, inputparent.as_deref())?,
620631
Commands::Dumpmeta {
621632
input,

0 commit comments

Comments
 (0)