Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Similar to the proc-ps implementation and unlike GNU/Coreutils, `uptime` provide

## `base32/base64/basenc`

Just like on macOS, `base32/base64/basenc` provides `-D` to decode data and `-o` to output to a file.
Just like on macOS, `base32/base64/basenc` provides `-D` to decode data.

## `shred`

Expand Down
1 change: 0 additions & 1 deletion src/uu/base32/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ base-common-read-error = read error: {$error}
base-common-help-decode = decode data
base-common-help-ignore-garbage = when decoding, ignore non-alphabetic characters
base-common-help-wrap = wrap encoded lines after COLS character (default {$default}, 0 to disable wrapping)
base-common-help-output-file = output to OUTPUT_FILE instead of stdout
23 changes: 2 additions & 21 deletions src/uu/base32/src/base_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use clap::{Arg, ArgAction, Command};
use std::ffi::OsString;
use std::fs::File;
use std::io::{self, BufWriter, ErrorKind, Read, Seek, Write};
use std::io::{self, ErrorKind, Read, Seek};
use std::path::{Path, PathBuf};
use uucore::display::Quotable;
use uucore::encoding::{
Expand All @@ -34,15 +34,13 @@ pub struct Config {
pub ignore_garbage: bool,
pub wrap_cols: Option<usize>,
pub to_read: Option<PathBuf>,
pub output_file: Option<PathBuf>,
}

pub mod options {
pub static DECODE: &str = "decode";
pub static WRAP: &str = "wrap";
pub static IGNORE_GARBAGE: &str = "ignore-garbage";
pub static FILE: &str = "file";
pub static OUTPUT_FILE: &str = "output_file";
}

impl Config {
Expand Down Expand Up @@ -88,17 +86,11 @@ impl Config {
})
.transpose()?;

let output_file = match options.get_one::<OsString>(options::OUTPUT_FILE) {
Some(value) if value != "-" => Some(Path::new(value).to_owned()),
_ => None,
};

Ok(Self {
decode: options.get_flag(options::DECODE),
ignore_garbage: options.get_flag(options::IGNORE_GARBAGE),
wrap_cols,
to_read,
output_file,
})
}
}
Expand Down Expand Up @@ -146,14 +138,6 @@ pub fn base_app(about: &'static str, usage: &str) -> Command {
.help(translate!("base-common-help-wrap", "default" => WRAP_DEFAULT))
.overrides_with(options::WRAP),
)
.arg(
Arg::new(options::OUTPUT_FILE)
.short('o')
.long(options::OUTPUT_FILE)
.help(translate!("base-common-help-output-file"))
.value_parser(clap::value_parser!(OsString))
.value_hint(clap::ValueHint::FilePath),
)
// "multiple" arguments are used to check whether there is more than one
// file passed in.
.arg(
Expand Down Expand Up @@ -210,10 +194,7 @@ pub fn handle_input<R: Read + Seek>(input: &mut R, format: Format, config: Confi
get_supports_fast_decode_and_encode(format, config.decode, has_padding);

let supports_fast_decode_and_encode_ref = supports_fast_decode_and_encode.as_ref();
let mut stdout_lock: Box<dyn Write> = match &config.output_file {
Some(path) => Box::new(BufWriter::new(File::create(path)?)),
None => Box::new(io::stdout().lock()),
};
let mut stdout_lock = io::stdout().lock();
if config.decode {
fast_decode::fast_decode(
read,
Expand Down
34 changes: 11 additions & 23 deletions src/uu/base64/benches/base64_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,64 @@
use divan::{Bencher, black_box};
use std::ffi::OsString;
use uu_base64::uumain;
use uucore::benchmark::{create_test_file, run_util_function, setup_test_file, text_data};
use uucore::benchmark::{create_test_file, run_util_function, text_data};

fn create_tmp_file(size_mb: usize) -> String {
let temp_dir = tempfile::tempdir().unwrap();
let data = text_data::generate_by_size(size_mb, 80);
let file_path = setup_test_file(&data);
let file_path = create_test_file(&data, temp_dir.path());
String::from(file_path.to_str().unwrap())
}

/// Benchmark for base64 encoding
#[divan::bench()]
fn b64_encode_synthetic(bencher: Bencher) {
let file_path_str = &create_tmp_file(50);
let file_path_str = &create_tmp_file(5_000);

bencher.bench(|| {
black_box(run_util_function(
uumain,
&["-o", "/dev/null", file_path_str],
));
black_box(run_util_function(uumain, &[file_path_str]));
});
}

// Benchmark for base64 decoding
#[divan::bench()]
fn b64_decode_synthetic(bencher: Bencher) {
let temp_dir = tempfile::tempdir().unwrap();
let file_path_str = &create_tmp_file(50);
let file_path_str = &create_tmp_file(5_000);
let in_file = create_test_file(b"", temp_dir.path());
let in_file_str = in_file.to_str().unwrap();
uumain(
[
OsString::from(uucore::util_name()),
OsString::from("-o"),
OsString::from(in_file_str),
OsString::from(file_path_str),
OsString::from(format!(">{in_file_str}")),
]
.iter()
.map(|x| (*x).clone()),
);

bencher.bench(|| {
black_box(run_util_function(
uumain,
&["-d", "-o", "/dev/null", in_file_str],
));
black_box(run_util_function(uumain, &["-d", in_file_str]));
});
}

// Benchmark different file sizes for base64 decoding ignoring garbage characters
#[divan::bench()]
fn b64_decode_ignore_garbage_synthetic(bencher: Bencher) {
let temp_dir = tempfile::tempdir().unwrap();
let file_path_str = &create_tmp_file(50);
let file_path_str = &create_tmp_file(5_000);
let in_file = create_test_file(b"", temp_dir.path());
let in_file_str = in_file.to_str().unwrap();
uumain(
[
OsString::from(uucore::util_name()),
OsString::from("-o"),
OsString::from(in_file_str),
OsString::from(file_path_str),
OsString::from(format!(">{in_file_str}")),
]
.iter()
.map(|x| (*x).clone()),
);

bencher.bench(|| {
black_box(run_util_function(
uumain,
&["-d", "-i", "-o", "/dev/null", in_file_str],
));
black_box(run_util_function(uumain, &["-d", "-i", in_file_str]));
});
}

Expand Down
Loading