Compare commits

..

No commits in common. "main" and "v0.4.3" have entirely different histories.
main ... v0.4.3

2 changed files with 14 additions and 8 deletions

View file

@ -12,6 +12,7 @@ use std::io::Cursor;
use std::{ use std::{
fmt::Debug, fmt::Debug,
io::{Read, Write}, io::{Read, Write},
usize,
}; };
struct Chunk { struct Chunk {
@ -30,8 +31,13 @@ impl Debug for Chunk {
} }
} }
impl Chunk {
fn kind_to_string(&self) -> String {
String::from_utf8_lossy(&self.kind).to_string()
}
}
pub fn fix(bytes: Vec<u8>) -> Vec<u8> { pub fn fix(mut bytes: Vec<u8>) -> Vec<u8> {
let mut bufread = Cursor::new(bytes); let mut bufread = Cursor::new(bytes);
// read the png header // read the png header
@ -41,7 +47,7 @@ pub fn fix(bytes: Vec<u8>) -> Vec<u8> {
let mut chunks = Vec::new(); let mut chunks = Vec::new();
let mut lenbuf = [0; 4]; let mut lenbuf = [0; 4];
while bufread.read_exact(&mut lenbuf).is_ok() { while let Ok(_) = bufread.read_exact(&mut lenbuf) {
let len = u32::from_be_bytes(lenbuf); let len = u32::from_be_bytes(lenbuf);
let mut kind = [0; 4]; let mut kind = [0; 4];

View file

@ -27,9 +27,9 @@ struct Args {
fn main() { fn main() {
// argument parsing yep // argument parsing yep
let args: Args = Args::parse(); let Args: Args = Args::parse();
let mut pathfr = args.path.clone(); let mut pathfr = Args.path.clone();
let debugmode = args.debug; let debugmode = Args.debug;
let mut filelist: Vec<PathBuf> = Vec::new(); let mut filelist: Vec<PathBuf> = Vec::new();
@ -59,7 +59,7 @@ fn main() {
filelist.push(path.display().to_string().parse().unwrap()); filelist.push(path.display().to_string().parse().unwrap());
} }
Err(e) => { Err(e) => {
eprintln!("Globbing error... uh oh... {}",e); eprintln!("Globbing error... uh oh...");
} }
} }
} }
@ -75,8 +75,8 @@ fn main() {
for thatpath in filelist { for thatpath in filelist {
println!("Filename: {:?}", thatpath); println!("Filename: {:?}", thatpath);
let frfr = read(&thatpath).expect("wtf the path doesnt exist"); let frfr = read(thatpath.to_owned()).expect("wtf the path doesnt exist");
let fr = lib::fix(frfr); let mut fr = lib::fix(frfr);
write(thatpath, fr).expect("file could not write btw"); write(thatpath, fr).expect("file could not write btw");
} }
} }