backport extend

This commit is contained in:
2024-09-06 03:59:00 +02:00
parent b181cde007
commit f11849b436
6 changed files with 73 additions and 42 deletions

View File

@@ -1,26 +1,9 @@
use std::{fs, path::Path};
use indicatif::{ProgressBar, ProgressStyle};
use std::{
fs::{self, File},
io::Read,
path::Path,
};
use crate::{global, structs};
pub fn file_blake3(file: &Path) -> std::io::Result<String> {
let mut blake3 = blake3::Hasher::new();
let mut file = File::open(file)?;
let mut buffer = [0; 1024];
loop {
let n = file.read(&mut buffer)?;
if n == 0 {
break;
}
blake3.update(&buffer[..n]);
}
Ok(blake3.finalize().to_string())
}
pub fn stdin() -> String {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
@@ -34,12 +17,6 @@ pub fn rev_to_int(rev: &str) -> u16 {
.unwrap_or(0)
}
pub fn fatal_error(error: &str) {
crate::println_error!("{}: {error}", prefix("error"));
stdin();
std::process::exit(1);
}
pub fn human_readable_bytes(bytes: u64) -> String {
let mut bytes = bytes as f64;
let mut i = 0;
@@ -62,10 +39,6 @@ pub fn pb_style_download(pb: &ProgressBar, state: bool) {
pb.set_style(style.unwrap());
}
pub fn cute_path(path: &Path) -> String {
path.to_str().unwrap().replace('\\', "/")
}
#[cfg(unix)]
pub fn is_program_in_path(program: &str) -> bool {
std::env::var_os("PATH")