Crates.io | transfer-progress |
lib.rs | transfer-progress |
version | 0.1.2 |
source | src |
created_at | 2021-08-19 10:17:47.561274 |
updated_at | 2021-10-07 15:57:13.692485 |
description | Easily monitor the transfer of bytes from a reader to a writer |
homepage | |
repository | https://github.com/mcb2003/transfer-progress-rs |
max_upload_size | |
id | 439555 |
size | 29,341 |
A small rust crate that allows you to monitor the speed, progress and estimated completion time of a transfer between a reader and a writer.
Internally, this spins up a new thread for each transfer, and uses the progress-streams crate to monitor it.
use std::{
fs::File,
io::{self, Read},
};
use transfer_progress::Transfer;
fn main() -> io::Result<()> {
let reader = File::open("/dev/urandom")?.take(1024 * 1024 * 1024); // 1 GiB
let writer = io::sink();
// Create the transfer monitor
let transfer = Transfer::new(reader, writer);
while !transfer.is_complete() {
std::thread::sleep(std::time::Duration::from_secs(1));
// {:#} makes Transfer use SI units (MiB instead of MB)
println!("{:#}", transfer);
}
// Catch any errors and retrieve the reader and writer
let (_reader, _writer) = transfer.finish()?;
Ok(())
}