Skip to main content

rars_format/
lib.rs

1#![cfg_attr(feature = "fast", feature(portable_simd))]
2
3//! Version-specific RAR archive format support.
4//!
5//! This crate contains the wire-format parsers, writers, recovery handling, and
6//! extraction orchestration used by the high-level `rars` facade. It keeps the
7//! concrete RAR families separate so callers can inspect format-specific header
8//! fields when they need that fidelity.
9
10pub mod detect;
11pub mod error;
12pub mod features;
13pub mod rar13;
14pub mod rar15_40;
15pub mod rar50;
16pub mod version;
17
18mod fast;
19mod io_util;
20#[cfg(feature = "parallel")]
21mod parallel;
22mod source;
23mod volume_extract;
24mod x86_filter_scan;
25
26pub use detect::{detect_archive_family, find_archive_start, ArchiveSignature, SFX_SCAN_LIMIT};
27pub use error::{Error, Result};
28pub use features::FeatureSet;
29pub use version::{ArchiveFamily, ArchiveVersion};
30
31#[derive(Debug, Clone, Copy, Default)]
32#[non_exhaustive]
33/// Options used while parsing or extracting archives.
34pub struct ArchiveReadOptions<'a> {
35    /// Password bytes used for encrypted headers or payloads.
36    pub password: Option<&'a [u8]>,
37    /// Optional RAR 5 whole-member buffered decode limit.
38    ///
39    /// Filtered RAR 5 members need whole-member transforms. Compressed members
40    /// above this limit use the streaming path and reject filtered streams
41    /// with an unsupported-feature error instead of buffering the full member.
42    pub rar50_buffered_decode_limit: Option<u64>,
43}
44
45impl<'a> ArchiveReadOptions<'a> {
46    /// Creates read options without a password.
47    pub fn new() -> Self {
48        Self::default()
49    }
50
51    /// Creates read options with a password.
52    pub fn with_password(password: &'a [u8]) -> Self {
53        Self {
54            password: Some(password),
55            ..Self::default()
56        }
57    }
58
59    /// Creates read options with an optional password.
60    pub fn with_optional_password(password: Option<&'a [u8]>) -> Self {
61        Self {
62            password,
63            ..Self::default()
64        }
65    }
66
67    /// Sets the RAR 5 whole-member buffered decode limit.
68    pub fn with_rar50_buffered_decode_limit(mut self, limit: u64) -> Self {
69        self.rar50_buffered_decode_limit = Some(limit);
70        self
71    }
72}