Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update master from dev #20

Merged
merged 11 commits into from
Apr 7, 2021
Prev Previous commit
Next Next commit
Moving bytes.rs implementation to utils.rs
  • Loading branch information
marcospb19 committed Apr 7, 2021
commit 3869c2502e3e6608c571e735fce866afca6f6fe0
71 changes: 0 additions & 71 deletions src/bytes.rs

This file was deleted.

13 changes: 4 additions & 9 deletions src/compressors/bzip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@ use std::{fs, io::Write, path::PathBuf};
use colored::Colorize;

use super::{Compressor, Entry};
use crate::{
bytes::Bytes,
extension::CompressionFormat,
file::File,
utils::{check_for_multiple_files, ensure_exists},
};
use crate::{extension::CompressionFormat, file::File, utils};

pub struct BzipCompressor;

impl BzipCompressor {
fn compress_files(files: Vec<PathBuf>, format: CompressionFormat) -> crate::Result<Vec<u8>> {
check_for_multiple_files(&files, &format)?;
utils::check_for_multiple_files(&files, &format)?;
let path = &files[0];
ensure_exists(path)?;
utils::ensure_exists(path)?;
let contents = {
let bytes = fs::read(path)?;
Self::compress_bytes(&*bytes)?
Expand All @@ -26,7 +21,7 @@ impl BzipCompressor {
"{}: compressed {:?} into memory ({})",
"info".yellow(),
&path,
Bytes::new(contents.len() as u64)
utils::Bytes::new(contents.len() as u64)
);

Ok(contents)
Expand Down
13 changes: 4 additions & 9 deletions src/compressors/gzip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ use std::{fs, io::Write, path::PathBuf};
use colored::Colorize;

use super::{Compressor, Entry};
use crate::{
bytes::Bytes,
extension::CompressionFormat,
file::File,
utils::{check_for_multiple_files, ensure_exists},
};
use crate::{extension::CompressionFormat, file::File, utils};

pub struct GzipCompressor;

Expand All @@ -17,10 +12,10 @@ impl GzipCompressor {
files: Vec<PathBuf>,
format: CompressionFormat,
) -> crate::Result<Vec<u8>> {
check_for_multiple_files(&files, &format)?;
utils::check_for_multiple_files(&files, &format)?;

let path = &files[0];
ensure_exists(path)?;
utils::ensure_exists(path)?;

let bytes = {
let bytes = fs::read(path)?;
Expand All @@ -31,7 +26,7 @@ impl GzipCompressor {
"{}: compressed {:?} into memory ({})",
"info".yellow(),
&path,
Bytes::new(bytes.len() as u64)
utils::Bytes::new(bytes.len() as u64)
);

Ok(bytes)
Expand Down
13 changes: 4 additions & 9 deletions src/compressors/lzma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ use std::{fs, io::Write, path::PathBuf};
use colored::Colorize;

use super::{Compressor, Entry};
use crate::{
bytes::Bytes,
extension::CompressionFormat,
file::File,
utils::{check_for_multiple_files, ensure_exists},
};
use crate::{extension::CompressionFormat, file::File, utils};

pub struct LzmaCompressor;

Expand All @@ -17,10 +12,10 @@ impl LzmaCompressor {
files: Vec<PathBuf>,
format: CompressionFormat,
) -> crate::Result<Vec<u8>> {
check_for_multiple_files(&files, &format)?;
utils::check_for_multiple_files(&files, &format)?;

let path = &files[0];
ensure_exists(path)?;
utils::ensure_exists(path)?;

let bytes = {
let bytes = fs::read(path)?;
Expand All @@ -31,7 +26,7 @@ impl LzmaCompressor {
"{}: compressed {:?} into memory ({})",
"info".yellow(),
&path,
Bytes::new(bytes.len() as u64)
utils::Bytes::new(bytes.len() as u64)
);

Ok(bytes)
Expand Down
4 changes: 2 additions & 2 deletions src/decompressors/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use colored::Colorize;
use tar::{self, Archive};

use super::decompressor::{DecompressionResult, Decompressor};
use crate::{bytes::Bytes, dialogs::Confirmation, file::File, utils};
use crate::{dialogs::Confirmation, file::File, utils};

#[derive(Debug)]
pub struct TarDecompressor;
Expand Down Expand Up @@ -48,7 +48,7 @@ impl TarDecompressor {
"{}: {:?} extracted. ({})",
"info".yellow(),
into.join(file.path()?),
Bytes::new(file.size())
utils::Bytes::new(file.size())
);

let file_path = fs::canonicalize(file_path)?;
Expand Down
4 changes: 2 additions & 2 deletions src/decompressors/to_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
use colored::Colorize;

use super::decompressor::{DecompressionResult, Decompressor};
use crate::{bytes::Bytes, extension::CompressionFormat, file::File, utils};
use crate::{extension::CompressionFormat, file::File, utils};

struct DecompressorToMemory;
pub struct GzipDecompressor;
Expand Down Expand Up @@ -38,7 +38,7 @@ impl DecompressorToMemory {
"{}: {:?} extracted into memory ({}).",
"info".yellow(),
path,
Bytes::new(bytes_read as u64)
utils::Bytes::new(bytes_read as u64)
);

Ok(buffer)
Expand Down
4 changes: 2 additions & 2 deletions src/decompressors/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use colored::Colorize;
use zip::{self, read::ZipFile, ZipArchive};

use super::decompressor::{DecompressionResult, Decompressor};
use crate::{bytes::Bytes, dialogs::Confirmation, file::File, utils};
use crate::{dialogs::Confirmation, file::File, utils};

#[cfg(unix)]
fn __unix_set_permissions(file_path: &Path, file: &ZipFile) {
Expand Down Expand Up @@ -76,7 +76,7 @@ impl ZipDecompressor {
"{}: \"{}\" extracted. ({})",
"info".yellow(),
file_path.display(),
Bytes::new(file.size())
utils::Bytes::new(file.size())
);

let mut output_file = fs::File::create(&file_path)?;
Expand Down
3 changes: 1 addition & 2 deletions src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{
use colored::Colorize;

use crate::{
bytes::Bytes,
cli::Command,
compressors::{
BzipCompressor, Compressor, Entry, GzipCompressor, LzmaCompressor, TarCompressor,
Expand Down Expand Up @@ -195,7 +194,7 @@ impl Evaluator {
"{}: writing to {:?}. ({})",
"info".yellow(),
output_path,
Bytes::new(bytes.len() as u64)
utils::Bytes::new(bytes.len() as u64)
);
fs::write(output_path, bytes)?;

Expand Down
4 changes: 2 additions & 2 deletions src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

use CompressionFormat::*;

use crate::utils::to_utf;
use crate::utils;

/// Represents the extension of a file, but only really caring about
/// compression formats (and .tar).
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Extension {
_ if ext == "gz" => Ok(Gzip),
_ if ext == "bz" || ext == "bz2" => Ok(Bzip),
_ if ext == "xz" || ext == "lz" || ext == "lzma" => Ok(Lzma),
other => Err(crate::Error::UnknownExtensionError(to_utf(other))),
other => Err(crate::Error::UnknownExtensionError(utils::to_utf(other))),
};

let (first_ext, second_ext) = match get_extension_from_filename(&file_name) {
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ pub mod cli;
pub mod evaluator;

// Private modules
mod bytes;
mod compressors;
mod decompressors;
mod dialogs;
mod error;
mod extension;
mod file;
mod test;
mod utils;

const VERSION: &str = "0.1.5";
Expand Down
Loading