Skip to content

Commit

Permalink
bugfix(map): fix parent compression map reading
Browse files Browse the repository at this point in the history
  • Loading branch information
chyyran committed Aug 13, 2022
1 parent 2290cf2 commit 32b46d6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions chd-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ mod tests {
f_out.write_all(&buf).expect("did not write")
}

#[test]
fn read_parent_test() {
let mut p = BufReader::new(File::open(".testimages/TombRaider.chd").expect(""));
let pchd = Chd::open(p, None).expect("parent");

let mut f = BufReader::new(File::open(".testimages/TombRaiderR1.chd").expect(""));

let chd = Chd::open(f, Some(Box::new(pchd))).expect("child");
}

#[test]
#[cfg(feature = "unsound_owning_iterators")]
fn hunk_iter_test() {
Expand Down
4 changes: 3 additions & 1 deletion chd-rs/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ fn read_map_v5<F: Read + Seek>(
last_parent = off;
}
CompressionTypeV5::CompressionParent1 => {
last_parent += (header.hunk_bytes / header.unit_bytes) as u64
last_parent += (header.hunk_bytes / header.unit_bytes) as u64;
map_slice[0] = CompressionTypeV5::CompressionParent as u8;
off = last_parent;
}
CompressionTypeV5::CompressionParent0 => {
map_slice[0] = CompressionTypeV5::CompressionParent as u8;
Expand Down
19 changes: 15 additions & 4 deletions rchdman/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ enum Commands {
/// input file name
#[clap(short, long, parse(try_from_os_str = validate_file_exists))]
input: PathBuf,
/// parent file name for input CHD
#[clap(short = 'p', long, parse(try_from_os_str = validate_file_exists))]
inputparent: Option<PathBuf>,
},
/// Verifies the integrity of a CHD
Verify {
Expand Down Expand Up @@ -452,12 +455,20 @@ fn info(input: &PathBuf, verbose: bool) -> anyhow::Result<()> {
Ok(())
}

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

let start = Instant::now();
let mut chd = Chd::open(&mut f, None)?;
let ipchd = ipf.map(|ipf| Chd::open(ipf, None));

let mut chd = if let Some(ip) = ipchd {
Chd::open(f, Some(Box::new(ip?)))?
} else {
Chd::open(f, None)?
};

let mut hunk_buf = chd.get_hunksized_buffer();
let mut cmp_buf = Vec::new();
let hunk_iter = chd.hunks();
Expand Down Expand Up @@ -615,7 +626,7 @@ fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
match &cli.command {
Commands::Info { input, verbose } => info(input, *verbose)?,
Commands::Benchmark { input } => benchmark(input)?,
Commands::Benchmark { input, inputparent } => benchmark(input, inputparent.as_ref())?,
Commands::Verify { input, inputparent } => verify(input, inputparent.as_deref())?,
Commands::Dumpmeta {
input,
Expand Down

0 comments on commit 32b46d6

Please sign in to comment.