Skip to content

Commit c3dcffe

Browse files
zRedShiftjessebraham
authored andcommitted
Use read_to_end to eliminate partial reads
1 parent aee5a82 commit c3dcffe

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

espflash/src/cli/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ pub fn write_bin_to_flash(opts: WriteBinToFlashOpts) -> Result<()> {
359359
flasher.board_info()?;
360360

361361
let mut f = File::open(&opts.bin_file).into_diagnostic()?;
362-
let metadata = fs::metadata(&opts.bin_file).into_diagnostic()?;
363-
let mut buffer = vec![0; metadata.len() as usize];
364-
f.read(&mut buffer).into_diagnostic()?;
362+
let size = f.metadata().into_diagnostic()?.len();
363+
let mut buffer = Vec::with_capacity(size.try_into().into_diagnostic()?);
364+
f.read_to_end(&mut buffer).into_diagnostic()?;
365365

366366
flasher.write_bin_to_flash(opts.addr, &buffer)?;
367367
Ok(())

0 commit comments

Comments
 (0)