Add piece hashing progress bar
type: added
This commit is contained in:
parent
c6cd78f565
commit
bdaec27caf
96
src/bytes.rs
96
src/bytes.rs
|
@ -1,53 +1,5 @@
|
|||
use crate::common::*;
|
||||
|
||||
impl Div<Bytes> for Bytes {
|
||||
type Output = u64;
|
||||
|
||||
fn div(self, rhs: Bytes) -> u64 {
|
||||
self.0 / rhs.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<u64> for Bytes {
|
||||
type Output = Bytes;
|
||||
|
||||
fn div(self, rhs: u64) -> Bytes {
|
||||
Bytes::from(self.0 / rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<u64> for Bytes {
|
||||
type Output = Bytes;
|
||||
|
||||
fn mul(self, rhs: u64) -> Self {
|
||||
Bytes::from(self.0 * rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl DivAssign<u64> for Bytes {
|
||||
fn div_assign(&mut self, rhs: u64) {
|
||||
self.0 /= rhs;
|
||||
}
|
||||
}
|
||||
|
||||
impl MulAssign<u64> for Bytes {
|
||||
fn mul_assign(&mut self, rhs: u64) {
|
||||
self.0 *= rhs;
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign<Bytes> for Bytes {
|
||||
fn add_assign(&mut self, rhs: Bytes) {
|
||||
self.0 += rhs.0;
|
||||
}
|
||||
}
|
||||
|
||||
impl SubAssign<u64> for Bytes {
|
||||
fn sub_assign(&mut self, rhs: u64) {
|
||||
self.0 -= rhs;
|
||||
}
|
||||
}
|
||||
|
||||
const KI: u64 = 1 << 10;
|
||||
const MI: u64 = KI << 10;
|
||||
const GI: u64 = MI << 10;
|
||||
|
@ -141,6 +93,54 @@ impl FromStr for Bytes {
|
|||
}
|
||||
}
|
||||
|
||||
impl Div<Bytes> for Bytes {
|
||||
type Output = u64;
|
||||
|
||||
fn div(self, rhs: Bytes) -> u64 {
|
||||
self.0 / rhs.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<u64> for Bytes {
|
||||
type Output = Bytes;
|
||||
|
||||
fn div(self, rhs: u64) -> Bytes {
|
||||
Bytes::from(self.0 / rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<u64> for Bytes {
|
||||
type Output = Bytes;
|
||||
|
||||
fn mul(self, rhs: u64) -> Self {
|
||||
Bytes::from(self.0 * rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl DivAssign<u64> for Bytes {
|
||||
fn div_assign(&mut self, rhs: u64) {
|
||||
self.0 /= rhs;
|
||||
}
|
||||
}
|
||||
|
||||
impl MulAssign<u64> for Bytes {
|
||||
fn mul_assign(&mut self, rhs: u64) {
|
||||
self.0 *= rhs;
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign<Bytes> for Bytes {
|
||||
fn add_assign(&mut self, rhs: Bytes) {
|
||||
self.0 += rhs.0;
|
||||
}
|
||||
}
|
||||
|
||||
impl SubAssign<u64> for Bytes {
|
||||
fn sub_assign(&mut self, rhs: u64) {
|
||||
self.0 -= rhs;
|
||||
}
|
||||
}
|
||||
|
||||
impl Sum for Bytes {
|
||||
fn sum<I>(iter: I) -> Self
|
||||
where
|
||||
|
|
|
@ -8,6 +8,7 @@ pub(crate) struct Hasher {
|
|||
piece_length: usize,
|
||||
pieces: PieceList,
|
||||
sha1: Sha1,
|
||||
progress_bar: ProgressBar,
|
||||
}
|
||||
|
||||
impl Hasher {
|
||||
|
@ -15,11 +16,12 @@ impl Hasher {
|
|||
files: &Files,
|
||||
md5sum: bool,
|
||||
piece_length: usize,
|
||||
progress_bar: ProgressBar,
|
||||
) -> Result<(Mode, PieceList), Error> {
|
||||
Self::new(md5sum, piece_length).hash_files(files)
|
||||
Self::new(md5sum, piece_length, progress_bar).hash_files(files)
|
||||
}
|
||||
|
||||
fn new(md5sum: bool, piece_length: usize) -> Self {
|
||||
fn new(md5sum: bool, piece_length: usize, progress_bar: ProgressBar) -> Self {
|
||||
Self {
|
||||
buffer: vec![0; piece_length],
|
||||
length: 0,
|
||||
|
@ -28,6 +30,7 @@ impl Hasher {
|
|||
sha1: Sha1::new(),
|
||||
piece_length,
|
||||
md5sum,
|
||||
progress_bar,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +125,8 @@ impl Hasher {
|
|||
}
|
||||
|
||||
remaining -= buffer.len().into_u64();
|
||||
|
||||
self.progress_bar.inc(to_buffer.into_u64());
|
||||
}
|
||||
|
||||
self.length += length;
|
||||
|
|
|
@ -199,7 +199,7 @@ impl Create {
|
|||
|
||||
errln!(env, "[1/3] \u{1F9FF} Searching for files…");
|
||||
|
||||
let style = ProgressStyle::default_spinner().template("{spinner} {msg}…");
|
||||
let style = ProgressStyle::default_spinner().template("{spinner:.green} {msg:.bold}…");
|
||||
|
||||
let spinner = ProgressBar::new_spinner().with_style(style);
|
||||
|
||||
|
@ -277,10 +277,20 @@ impl Create {
|
|||
|
||||
errln!(env, "[2/3] \u{1F9EE} Hashing pieces…");
|
||||
|
||||
let style = ProgressStyle::default_bar()
|
||||
.template(
|
||||
"{spinner:.green} [{elapsed_precise}] \u{2588}{bar:40.cyan/blue}\u{2588} \
|
||||
{bytes}/{total_bytes} ({bytes_per_sec}, {eta})",
|
||||
)
|
||||
.progress_chars("\u{2593}\u{2592}\u{2591}");
|
||||
|
||||
let progress_bar = ProgressBar::new(files.total_size().count()).with_style(style);
|
||||
|
||||
let (mode, pieces) = Hasher::hash(
|
||||
&files,
|
||||
self.md5sum,
|
||||
piece_length.as_piece_length()?.into_usize(),
|
||||
progress_bar,
|
||||
)?;
|
||||
|
||||
errln!(env, "[3/3] \u{1F4BE} Writing metainfo to {}…", output);
|
||||
|
|
Loading…
Reference in New Issue
Block a user