Support LZ4 compression for external CMDs

This commit is contained in:
2024-09-28 15:00:18 +02:00
parent 1529e279ab
commit 90e6f40705
2 changed files with 24 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
use colored::*;
use envmnt::{ExpandOptions, ExpansionType};
use std::{boxed::Box, io::{BufRead, BufReader, BufWriter, Read, Write}, path::PathBuf, str::FromStr};
use std::{boxed::Box, fs::OpenOptions, io::{BufRead, BufReader, BufWriter, Read, Write}, path::PathBuf, str::FromStr};
pub mod bits;
pub mod compress;
@@ -241,6 +241,13 @@ pub fn read_file_to_string(file_path: &PathBuf) -> Result<String, Error> {
}
}
pub fn write_file(file_path: &PathBuf, data: Vec<u8>) -> Result<(), Error> {
let mut file = OpenOptions::new().read(true).write(true).truncate(true).create(true).open(file_path)?;
file.write_all(data.as_slice())?;
Ok(())
}
fn create_file_read_error<T>(file_path: &PathBuf, error: std::io::Error) -> Result<T, Error> {
Err(Error::from_text(format!("Failed reading file {} with error: \"{}\"", file_path.display(), error)))
}