Skip to main content

nzbdav_rar/
lib.rs

1//! Pure Rust RAR4/RAR5 header-only parser.
2//!
3//! nzbdav only needs to read archive headers to discover contained files —
4//! it never decompresses data (files must be stored with compression method m0).
5//! Pure Rust implementation — no external archive libraries required.
6
7pub mod crypto;
8pub mod error;
9pub mod header;
10pub mod parser;
11pub mod rar4;
12pub mod rar5;
13
14pub use error::{RarError, Result};
15pub use header::{ArchiveHeader, EndArchiveHeader, FileHeader, RarHeader, ServiceHeader};
16pub use parser::{parse_all_headers, parse_headers};
17
18/// RAR4 magic bytes: `Rar!\x1a\x07\x00`
19pub const RAR4_MAGIC: &[u8] = &[0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00];
20
21/// RAR5 magic bytes: `Rar!\x1a\x07\x01\x00`
22pub const RAR5_MAGIC: &[u8] = &[0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00];
23
24pub fn detect_version(header: &[u8]) -> Option<RarVersion> {
25    if header.len() >= RAR5_MAGIC.len() && header[..RAR5_MAGIC.len()] == *RAR5_MAGIC {
26        Some(RarVersion::Rar5)
27    } else if header.len() >= RAR4_MAGIC.len() && header[..RAR4_MAGIC.len()] == *RAR4_MAGIC {
28        Some(RarVersion::Rar4)
29    } else {
30        None
31    }
32}
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub enum RarVersion {
36    Rar4,
37    Rar5,
38}