diff --git a/src/bytes.rs b/src/bytes.rs index e79375b..ac1be6e 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -2,7 +2,7 @@ use std::cmp; const UNITS: [&str; 4] = ["B", "kB", "MB", "GB"]; -struct Bytes { +pub struct Bytes { bytes: f64, } diff --git a/src/compressors/bzip.rs b/src/compressors/bzip.rs index d2a20d0..ab63898 100644 --- a/src/compressors/bzip.rs +++ b/src/compressors/bzip.rs @@ -5,6 +5,7 @@ use colored::Colorize; use super::{Compressor, Entry}; use crate::{ extension::CompressionFormat, + bytes::Bytes, file::File, utils::{check_for_multiple_files, ensure_exists}, }; @@ -22,10 +23,10 @@ impl BzipCompressor { }; println!( - "{}: compressed {:?} into memory ({} bytes)", + "{}: compressed {:?} into memory ({})", "info".yellow(), &path, - contents.len() + Bytes::new(contents.len() as u64) ); Ok(contents) diff --git a/src/compressors/gzip.rs b/src/compressors/gzip.rs index 5dc0ee2..b01208b 100644 --- a/src/compressors/gzip.rs +++ b/src/compressors/gzip.rs @@ -6,6 +6,7 @@ use super::{Compressor, Entry}; use crate::{ extension::CompressionFormat, file::File, + bytes::Bytes, utils::{check_for_multiple_files, ensure_exists}, }; @@ -27,10 +28,10 @@ impl GzipCompressor { }; println!( - "{}: compressed {:?} into memory ({} bytes)", + "{}: compressed {:?} into memory ({})", "info".yellow(), &path, - bytes.len() + Bytes::new(bytes.len() as u64) ); Ok(bytes) diff --git a/src/compressors/lzma.rs b/src/compressors/lzma.rs index f68a197..d622ac4 100644 --- a/src/compressors/lzma.rs +++ b/src/compressors/lzma.rs @@ -6,6 +6,7 @@ use super::{Compressor, Entry}; use crate::{ extension::CompressionFormat, file::File, + bytes::Bytes, utils::{check_for_multiple_files, ensure_exists}, }; @@ -27,10 +28,10 @@ impl LzmaCompressor { }; println!( - "{}: compressed {:?} into memory ({} bytes)", + "{}: compressed {:?} into memory ({})", "info".yellow(), &path, - bytes.len() + Bytes::new(bytes.len() as u64) ); Ok(bytes) diff --git a/src/decompressors/tar.rs b/src/decompressors/tar.rs index fabbea8..2c7ef64 100644 --- a/src/decompressors/tar.rs +++ b/src/decompressors/tar.rs @@ -8,7 +8,7 @@ use colored::Colorize; use tar::{self, Archive}; use super::decompressor::{DecompressionResult, Decompressor}; -use crate::{dialogs::Confirmation, file::File, utils}; +use crate::{dialogs::Confirmation, file::File, bytes::Bytes, utils}; #[derive(Debug)] pub struct TarDecompressor {} @@ -45,10 +45,10 @@ impl TarDecompressor { file.unpack_in(into)?; println!( - "{}: {:?} extracted. ({} bytes)", + "{}: {:?} extracted. ({})", "info".yellow(), into.join(file.path()?), - file.size() + Bytes::new(file.size()) ); let file_path = fs::canonicalize(file_path)?; diff --git a/src/decompressors/to_memory.rs b/src/decompressors/to_memory.rs index 810a29c..aa82daf 100644 --- a/src/decompressors/to_memory.rs +++ b/src/decompressors/to_memory.rs @@ -7,7 +7,7 @@ use colored::Colorize; use super::decompressor::{DecompressionResult, Decompressor}; use crate::utils; -// use niffler; +use crate::bytes::Bytes; use crate::{extension::CompressionFormat, file::File}; struct DecompressorToMemory {} @@ -37,10 +37,10 @@ impl DecompressorToMemory { let bytes_read = reader.read_to_end(&mut buffer)?; println!( - "{}: {:?} extracted into memory ({} bytes).", + "{}: {:?} extracted into memory ({}).", "info".yellow(), path, - bytes_read + Bytes::new(bytes_read as u64) ); Ok(buffer) diff --git a/src/decompressors/zip.rs b/src/decompressors/zip.rs index 48971a8..7cfabf2 100644 --- a/src/decompressors/zip.rs +++ b/src/decompressors/zip.rs @@ -8,7 +8,7 @@ use colored::Colorize; use zip::{self, read::ZipFile, ZipArchive}; use super::decompressor::{DecompressionResult, Decompressor}; -use crate::{dialogs::Confirmation, file::File, utils}; +use crate::{dialogs::Confirmation, file::File, bytes::Bytes, utils}; #[cfg(unix)] fn __unix_set_permissions(file_path: &Path, file: &ZipFile) { @@ -73,10 +73,10 @@ impl ZipDecompressor { } } println!( - "{}: \"{}\" extracted. ({} bytes)", + "{}: \"{}\" extracted. ({})", "info".yellow(), file_path.display(), - file.size() + Bytes::new(file.size()) ); let mut output_file = fs::File::create(&file_path)?; diff --git a/src/evaluator.rs b/src/evaluator.rs index 8d01625..9d68f5d 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -7,6 +7,7 @@ use std::{ use colored::Colorize; use crate::{ + bytes::Bytes, cli::{VERSION, Command}, compressors::{ Entry, Compressor, BzipCompressor, GzipCompressor, LzmaCompressor, TarCompressor, @@ -199,10 +200,10 @@ impl Evaluator { }; println!( - "{}: writing to {:?}. ({} bytes)", + "{}: writing to {:?}. ({})", "info".yellow(), output_path, - bytes.len() + Bytes::new(bytes.len() as u64) ); fs::write(output_path, bytes)?;