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 {
|
if d.0 == w {
|
||||||
wch = true;
|
wch = true;
|
||||||
}
|
}
|
||||||
} else { wch = true; }
|
} else {
|
||||||
|
wch = true;
|
||||||
|
}
|
||||||
if let Some(h) = args.height.clone() {
|
if let Some(h) = args.height.clone() {
|
||||||
if d.1 == h {
|
if d.1 == h {
|
||||||
hch = true;
|
hch = true;
|
||||||
}
|
}
|
||||||
} else { hch = true; }
|
} else {
|
||||||
|
hch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if wch && hch {
|
||||||
|
chk = false;
|
||||||
}
|
}
|
||||||
if wch && hch { chk = false; }
|
|
||||||
}
|
}
|
||||||
p
|
p
|
||||||
} else {
|
} else {
|
||||||
|
@ -101,32 +107,28 @@ fn main() -> Result<(), Error> {
|
||||||
if let Some(out) = args.out.to_owned() {
|
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
|
// 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.
|
// locking up large amounts of system ram running on a large file.
|
||||||
let mut contents;
|
let contents = {
|
||||||
{
|
let mut c;
|
||||||
// open readfile after this line
|
|
||||||
let mut f = OpenOptions::new()
|
let mut f = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.open(&pick)
|
.open(&pick)
|
||||||
.expect("unable to open readfile");
|
.expect("unable to open readfile");
|
||||||
let m = metadata(&pick).expect("unable to read metadata");
|
let m = metadata(&pick).expect("unable to read metadata");
|
||||||
contents = vec![0; m.len() as usize];
|
c = vec![0; m.len() as usize];
|
||||||
f.read(&mut contents).expect("buffer overflow");
|
f.read(&mut c).expect("buffer overflow");
|
||||||
} // readfile closes here due to falling out of scope
|
c
|
||||||
let contents = contents; // remove mutability
|
};
|
||||||
{
|
{
|
||||||
// open outfile after this line
|
|
||||||
let mut f = OpenOptions::new()
|
let mut f = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
.open(out.as_str())
|
.open(out.as_str())
|
||||||
.expect("unable to open outfile");
|
.expect("unable to open outfile");
|
||||||
f.set_len(0u64).expect("unable to truncate file"); // just call ftruncate() on the poor
|
f.set_len(0u64).expect("unable to truncate file");
|
||||||
// thing
|
|
||||||
f.write_all(&contents).expect("unable to write to outfile");
|
f.write_all(&contents).expect("unable to write to outfile");
|
||||||
f.flush().expect(
|
f.flush()
|
||||||
"unable to flush outfile (if this happens something has gone *terribly* wrong)",
|
.expect("unable to flush outfile (something has gone comically wrong)");
|
||||||
);
|
}
|
||||||
} // outfile closes here due to falling out of scope
|
|
||||||
} else {
|
} else {
|
||||||
println!("{}", pick.display());
|
println!("{}", pick.display());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue