Merge branch 'main' of github.com:TudbuT/qft

This commit is contained in:
Daniella / Tove 2022-10-03 18:48:21 +02:00
commit 783116217d

View file

@ -400,6 +400,7 @@ pub fn sender<F: Fn(f32)>(args: &Vec<String>, on_progress: F) {
sc.write_safe(&len.to_be_bytes())
.expect("unable to send file length");
println!("Length: {}", &len);
let mut time_elapsed = unix_millis();
loop {
let read = file.read(&mut buf).expect("file read error");
if read == 0 && !env::var("QFT_STREAM").is_ok() {
@ -412,8 +413,10 @@ pub fn sender<F: Fn(f32)>(args: &Vec<String>, on_progress: F) {
sc.write_safe(&buf[..read]).expect("send error");
bytes_sent += read as u64;
if (bytes_sent % (br * 20) as u64) < (br as u64) {
print!("\r\x1b[KSent {} bytes", bytes_sent);
print!("\r\x1b[KSent {} bytes; Speed: {} kb/s",
bytes_sent, br as usize * 20 / (unix_millis() - time_elapsed) as usize );
stdout().flush().unwrap();
time_elapsed = unix_millis();
}
if unix_millis() - last_update > 100 {
on_progress((bytes_sent + begin) as f32 / len as f32);
@ -466,6 +469,7 @@ pub fn receiver<F: Fn(f32)>(args: &Vec<String>, on_progress: F) {
]);
file.set_len(len).expect("unable to set file length");
println!("Length: {}", &len);
let mut time_elapsed = unix_millis();
loop {
let (mbuf, amount) = sc.read_safe(buf).expect("read error");
let buf = &mbuf.leak()[..amount];
@ -479,8 +483,10 @@ pub fn receiver<F: Fn(f32)>(args: &Vec<String>, on_progress: F) {
file.flush().expect("file flush error");
bytes_received += amount as u64;
if (bytes_received % (br * 20) as u64) < (br as u64) {
print!("\r\x1b[KReceived {} bytes", bytes_received);
print!("\r\x1b[KReceived {} bytes; Speed: {} kb/s",
bytes_received, br as usize * 20 / (unix_millis() - time_elapsed) as usize );
stdout().flush().unwrap();
time_elapsed = unix_millis();
}
if unix_millis() - last_update > 100 {
on_progress((bytes_received + begin) as f32 / len as f32);