minor updates for improved performance, probably
This commit is contained in:
parent
9f0574f138
commit
a4f1a9ed67
36
src/main.rs
36
src/main.rs
|
@ -83,14 +83,20 @@ fn main() -> Result<(), Error> {
|
|||
if d.0 == w {
|
||||
wch = true;
|
||||
}
|
||||
} else { wch = true; }
|
||||
} else {
|
||||
wch = true;
|
||||
}
|
||||
if let Some(h) = args.height.clone() {
|
||||
if d.1 == h {
|
||||
hch = true;
|
||||
}
|
||||
} else { hch = true; }
|
||||
} else {
|
||||
hch = true;
|
||||
}
|
||||
}
|
||||
if wch && hch {
|
||||
chk = false;
|
||||
}
|
||||
if wch && hch { chk = false; }
|
||||
}
|
||||
p
|
||||
} else {
|
||||
|
@ -101,32 +107,28 @@ fn main() -> Result<(), Error> {
|
|||
if let Some(out) = args.out.to_owned() {
|
||||
// TODO: setup a constant size buffer and read/write that many bytes at a time to prevent
|
||||
// locking up large amounts of system ram running on a large file.
|
||||
let mut contents;
|
||||
{
|
||||
// open readfile after this line
|
||||
let contents = {
|
||||
let mut c;
|
||||
let mut f = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(&pick)
|
||||
.expect("unable to open readfile");
|
||||
let m = metadata(&pick).expect("unable to read metadata");
|
||||
contents = vec![0; m.len() as usize];
|
||||
f.read(&mut contents).expect("buffer overflow");
|
||||
} // readfile closes here due to falling out of scope
|
||||
let contents = contents; // remove mutability
|
||||
c = vec![0; m.len() as usize];
|
||||
f.read(&mut c).expect("buffer overflow");
|
||||
c
|
||||
};
|
||||
{
|
||||
// open outfile after this line
|
||||
let mut f = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(out.as_str())
|
||||
.expect("unable to open outfile");
|
||||
f.set_len(0u64).expect("unable to truncate file"); // just call ftruncate() on the poor
|
||||
// thing
|
||||
f.set_len(0u64).expect("unable to truncate file");
|
||||
f.write_all(&contents).expect("unable to write to outfile");
|
||||
f.flush().expect(
|
||||
"unable to flush outfile (if this happens something has gone *terribly* wrong)",
|
||||
);
|
||||
} // outfile closes here due to falling out of scope
|
||||
f.flush()
|
||||
.expect("unable to flush outfile (something has gone comically wrong)");
|
||||
}
|
||||
} else {
|
||||
println!("{}", pick.display());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue