diff --git a/Cargo.lock b/Cargo.lock index fbf6f1e..02917bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "pngrip" -version = "0.1.0" +version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index a873f22..58a67ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pngrip" -version = "0.1.0" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index eef474c..a51be9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,11 +58,14 @@ fn rip_png(path: &Path, destination: &Path) { let mut start_pos: usize = 0; let mut last_pos: usize = 0; let mut end_pos: usize = 0; - for i in 0..file_bytes.len()-png_identifier.len() { - if file_bytes[i..i + png_identifier.len()] == png_identifier { - start_pos = i; + for i in 0..file_bytes.len()-iend_identifier.len() { + if i < file_bytes.len() - png_identifier.len() { + if file_bytes[i..i + png_identifier.len()] == png_identifier { + start_pos = i; + } } + if file_bytes[i..i + iend_identifier.len()] == iend_identifier { end_pos = i + iend_identifier.len(); } @@ -70,7 +73,6 @@ fn rip_png(path: &Path, destination: &Path) { if start_pos < end_pos && start_pos != last_pos { last_pos = start_pos; image_count += 1; - // println!("[INFO] Found PNG at {}->{} ({} bytes)", start_pos, end_pos, end_pos - start_pos); let mut ripped_image_file; let ripped_image_filename = format!("{}_{}.png", filename, image_count); @@ -94,7 +96,6 @@ fn rip_png(path: &Path, destination: &Path) { } } - println!("[INFO] Ripped {} images from \"{}\" in total", image_count, filename); }