1 //! Contains RAR-specific building and unpacking functions
5 use unrar::{self, Archive};
7 use crate::{info, list::FileInArchive, warning};
9 /// Unpacks the archive given by `archive_path` into the folder given by `output_folder`.
10 /// Assumes that output_folder is empty
11 pub fn unpack_archive(archive_path: &Path, output_folder: &Path, quiet: bool) -> crate::Result<usize> {
12 assert!(output_folder.read_dir().expect("dir exists").count() == 0);
14 let mut archive = Archive::new(archive_path).open_for_processing()?;
17 while let Some(header) = archive.read_header()? {
18 let entry = header.entry();
19 archive = if entry.is_file() {
24 entry.filename.display(),
29 header.extract_with_base(output_folder)?
38 /// List contents of `archive_path`, returning a vector of archive entries
39 pub fn list_archive(archive_path: &Path) -> impl Iterator<Item = crate::Result<FileInArchive>> {
40 Archive::new(archive_path)
42 .expect("cannot open archive")
45 let is_dir = item.is_directory();
46 let path = item.filename;
48 Ok(FileInArchive { path, is_dir })
52 pub fn no_compression_notice() {
53 const MESSAGE: &str = "Creating '.rar' archives is not supported due to licensing restrictions";
55 warning!("{}", MESSAGE);