ind_file/
lib.rs

1use std::fs::File;
2use std::io::Write;
3use std::path::PathBuf;
4use indicatif::ProgressBar;
5
6pub fn write_with_progress(pb: &mut ProgressBar, bytes: &[u8], file_path: PathBuf, chunk_size: usize) -> anyhow::Result<()> {
7	let mut file = File::create(file_path)?;
8	pb.set_length(bytes.len().try_into()?);
9	pb.set_position(0);
10	for chunk in bytes.chunks(chunk_size) {
11		file.write_all(chunk)?;
12		pb.inc(chunk.len().try_into()?);
13	}
14	Ok(())
15}