Skip to content

Commit

Permalink
style: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kruserr committed Oct 11, 2024
1 parent 0c0ed9e commit 01943dc
Showing 1 changed file with 58 additions and 50 deletions.
108 changes: 58 additions & 50 deletions i6-pack/src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,52 @@ use zstd::stream::{decode_all, encode_all};
use zstd::Encoder;

pub fn create_tar_archive<P: AsRef<Path>>(
folder: P,
tar_file: &str,
folder: P,
tar_file: &str,
) -> io::Result<()> {
let tar_gz = File::create(tar_file)?;
let mut archive = Builder::new(tar_gz);

for entry in WalkDir::new(folder) {
let entry = match entry {
Ok(e) => e,
Err(e) => {
eprintln!("Warning: failed to read directory entry: {}", e);
continue;
let tar_gz = File::create(tar_file)?;
let mut archive = Builder::new(tar_gz);

for entry in WalkDir::new(folder) {
let entry = match entry {
Ok(e) => e,
Err(e) => {
eprintln!("Warning: failed to read directory entry: {}", e);
continue;
}
};
let path = entry.path();
if path.is_symlink() {
match std::fs::read_link(path) {
Ok(target) => {
if target.exists() {
if let Err(e) = archive.append_path_with_name(&target, path) {
eprintln!("Warning: failed to append symlink {:?}: {}", path, e);
}
};
let path = entry.path();
if path.is_symlink() {
match std::fs::read_link(path) {
Ok(target) => {
if target.exists() {
if let Err(e) = archive.append_path_with_name(&target, path) {
eprintln!("Warning: failed to append symlink {:?}: {}", path, e);
}
} else {
eprintln!("Warning: symlink target {:?} does not exist, skipping", target);
}
}
Err(e) => {
eprintln!("Warning: failed to read symlink {:?}, skipping: {}", path, e);
}
}
} else if path.exists() {
if let Err(e) = archive.append_path(path) {
eprintln!("Warning: failed to append path {:?}: {}", path, e);
}
} else {
eprintln!("Warning: file {:?} does not exist, skipping", path);
} else {
eprintln!(
"Warning: symlink target {:?} does not exist, skipping",
target
);
}
}
Err(e) => {
eprintln!(
"Warning: failed to read symlink {:?}, skipping: {}",
path, e
);
}
}
} else if path.exists() {
if let Err(e) = archive.append_path(path) {
eprintln!("Warning: failed to append path {:?}: {}", path, e);
}
} else {
eprintln!("Warning: file {:?} does not exist, skipping", path);
}
}

Ok(())
Ok(())
}

pub fn extract_tar_archive(tar_file: &str, output_dir: &str) -> io::Result<()> {
Expand All @@ -64,25 +70,28 @@ pub fn extract_tar_archive(tar_file: &str, output_dir: &str) -> io::Result<()> {
}

pub fn compress_tar_file(
tar_file: &str,
compressed_file: &str,
tar_file: &str,
compressed_file: &str,
) -> io::Result<()> {
let tar = File::open(tar_file)?;
let compressed = File::create(compressed_file)?;
let mut tar_reader = tar;
let mut compressed_writer = compressed;
let compression_level = 18;
let tar = File::open(tar_file)?;
let compressed = File::create(compressed_file)?;
let mut tar_reader = tar;
let mut compressed_writer = compressed;
let compression_level = 18;

let mut zstd = zstd::stream::write::Encoder::new(&mut compressed_writer, compression_level)?;
zstd.multithread(num_cpus::get() as u32)?;
let mut zstd = zstd::stream::write::Encoder::new(
&mut compressed_writer,
compression_level,
)?;
zstd.multithread(num_cpus::get() as u32)?;

zstd.long_distance_matching(true)?;
zstd.window_log(31)?;
zstd.long_distance_matching(true)?;
zstd.window_log(31)?;

io::copy(&mut tar_reader, &mut zstd)?;
zstd.finish()?;
io::copy(&mut tar_reader, &mut zstd)?;
zstd.finish()?;

Ok(())
Ok(())
}

pub fn decompress_file_v1(
Expand All @@ -104,7 +113,6 @@ pub fn decompress_file(
let mut compressed_reader = compressed;
let mut decompressed_writer = File::create(output_file)?;


let mut zstd = zstd::stream::read::Decoder::new(&mut compressed_reader)?;
zstd.window_log_max(31)?;

Expand Down

0 comments on commit 01943dc

Please sign in to comment.