1 //! Contains RAR-specific building and unpacking functions
8 error::{Error, Result},
13 /// Unpacks the archive given by `archive_path` into the folder given by `output_folder`.
14 /// Assumes that output_folder is empty
15 pub fn unpack_archive(
18 password: Option<&[u8]>,
20 ) -> crate::Result<usize> {
21 assert!(output_folder.read_dir().expect("dir exists").count() == 0);
23 let archive = match password {
24 Some(password) => Archive::with_password(archive_path, password),
25 None => Archive::new(archive_path),
28 let mut archive = archive.open_for_processing()?;
31 while let Some(header) = archive.read_header()? {
32 let entry = header.entry();
33 archive = if entry.is_file() {
37 entry.filename.display(),
42 header.extract_with_base(output_folder)?
51 /// List contents of `archive_path`, returning a vector of archive entries
54 password: Option<&[u8]>,
55 ) -> Result<impl Iterator<Item = Result<FileInArchive>>> {
56 let archive = match password {
57 Some(password) => Archive::with_password(archive_path, password),
58 None => Archive::new(archive_path),
61 Ok(archive.open_for_listing()?.map(|item| {
63 let is_dir = item.is_directory();
64 let path = item.filename;
66 Ok(FileInArchive { path, is_dir })
70 pub fn no_compression() -> Error {
71 Error::UnsupportedFormat {
72 reason: "Creating RAR archives is not allowed due to licensing restrictions.".into(),