Skip to content

Commit

Permalink
feat: Show more numbers in human readable form (#790)
Browse files Browse the repository at this point in the history
This shows sizes in KiB, MiB etc.  Also adds a few totals and transfer
summaries.
  • Loading branch information
flub committed Feb 23, 2023
1 parent 9076443 commit a0b7c26
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,12 @@ async fn provide_interactive(
let (db, hash) = provider::create_collection(sources).await?;

println!("Collection: {}\n", Blake3Cid::new(hash));
let mut total_size = 0;
for (_, path, size) in db.blobs() {
println!("- {}: {} bytes", path.display(), size);
total_size += size;
println!("- {}: {}", path.display(), HumanBytes(size));
}
println!("Total: {}", HumanBytes(total_size));
println!();
let mut builder = provider::Provider::builder(db)
.keypair(keypair)
Expand All @@ -332,15 +335,9 @@ async fn provide_interactive(
}
let provider = builder.spawn()?;

out_writer
.println(format!("PeerID: {}", provider.peer_id()))
.await;
out_writer
.println(format!("Auth token: {}", provider.auth_token()))
.await;
out_writer
.println(format!("All-in-one ticket: {}", provider.ticket(hash)))
.await;
println!("PeerID: {}", provider.peer_id());
println!("Auth token: {}", provider.auth_token());
println!("All-in-one ticket: {}", provider.ticket(hash));
provider.await?;

// Drop tempath to signal it can be destroyed
Expand Down Expand Up @@ -488,7 +485,12 @@ async fn get_interactive(

pb.finish_and_clear();
out_writer
.println(format!("Done in {}", HumanDuration(stats.elapsed)))
.println(format!(
"Transferred {} in {}, {}/s",
HumanBytes(stats.data_len),
HumanDuration(stats.elapsed),
HumanBytes((stats.data_len as f64 / stats.elapsed.as_secs_f64()) as u64),
))
.await;

Ok(())
Expand Down

0 comments on commit a0b7c26

Please sign in to comment.