Expand description
§rar-stream
A high-performance RAR archive streaming library for Rust, Node.js, and browsers.
This library provides streaming access to files within RAR archives, optimized for video streaming with fast seeking via binary search. It supports both RAR4 (1.5-4.x) and RAR5 (5.0+) formats with full decompression and optional encryption support.
§Features
| Feature | Default | Description |
|---|---|---|
async | No | Async archive reading via tokio (RarFilesPackage, InnerFile) |
crypto | No | Encrypted archive support (AES-256 for RAR5, AES-128 for RAR4) |
napi | No | Node.js native bindings via napi-rs (implies async + parallel) |
wasm | No | Browser WebAssembly bindings |
§Supported Formats
| Format | Versions | Compression | Encryption |
|---|---|---|---|
| RAR4 | 1.5-4.x | LZSS, PPMd | AES-128-CBC (SHA-1 KDF) |
| RAR5 | 5.0+ | LZSS + filters | AES-256-CBC (PBKDF2-HMAC-SHA256) |
§Architecture
The library is organized into layers:
┌─────────────────────────────────────────────────────┐
│ Application Layer (async feature) │
│ RarFilesPackage → InnerFile → read_to_end() │
├─────────────────────────────────────────────────────┤
│ Parsing Layer │
│ MarkerHeader → ArchiveHeader → FileHeader │
├─────────────────────────────────────────────────────┤
│ Decompression Layer │
│ Rar29Decoder (RAR4) / Rar5Decoder (RAR5) │
├─────────────────────────────────────────────────────┤
│ Crypto Layer (crypto feature) │
│ Rar4Crypto (AES-128) / Rar5Crypto (AES-256) │
└─────────────────────────────────────────────────────┘§Quick Start
§High-Level API (requires async feature)
ⓘ
use rar_stream::{RarFilesPackage, ParseOptions, LocalFileMedia, FileMedia};
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let file: Arc<dyn FileMedia> = Arc::new(LocalFileMedia::new("archive.rar")?);
let package = RarFilesPackage::new(vec![file]);
let files = package.parse(ParseOptions::default()).await?;
for f in &files {
println!("{}: {} bytes", f.name, f.length);
}
let content = files[0].read_to_end().await?;
Ok(())
}§Low-Level Decompression (no features required)
use rar_stream::Rar29Decoder;
// Create a decoder for RAR4 LZSS data
let mut decoder = Rar29Decoder::new();
// Decompress raw compressed data (obtained from file header)
// let decompressed = decoder.decompress(&compressed_data, expected_size)?;§Encrypted Archives
With the crypto feature, you can read encrypted archives:
ⓘ
use rar_stream::{RarFilesPackage, ParseOptions};
let opts = ParseOptions {
password: Some("secret".to_string()),
..Default::default()
};
let files = package.parse(opts).await?;
// Content is automatically decrypted and decompressed
let content = files[0].read_decompressed().await?;§Error Handling
All operations return Result<T, RarError>. Common errors include:
RarError::InvalidSignature- Not a valid RAR fileRarError::PasswordRequired- Encrypted archive, no password providedRarError::DecryptionFailed- Wrong password or corrupt dataRarError::DecompressionNotSupported- Unsupported compression method
§Module Overview
error- Error types for all operationsparsing- RAR header parsing (both RAR4 and RAR5)decompress- Decompression algorithms (LZSS, PPMd, filters)crypto- Encryption/decryption (requirescryptofeature)formats- Low-level format constants and utilities
§Performance Notes
- Streaming: Files are read on-demand, not loaded entirely into memory
- Binary search: Chunk lookup uses binary search for O(log n) seeking
- Zero-copy parsing: Headers are parsed without unnecessary allocations
- Cached decompression: Decompressed data is cached for repeated reads
§Browser/WASM Usage
With the wasm feature, the library compiles to WebAssembly for browser use.
See the npm package documentation for JavaScript API details.
Re-exports§
pub use error::RarError;pub use decompress::CompressionMethod;pub use decompress::DecompressError;pub use decompress::Rar29Decoder;
Modules§
- crypto
crypto - Cryptographic support for encrypted RAR archives.
- decompress
- RAR decompression algorithms.
- error
- Error types for RAR parsing and decompression.
- formats
- RAR format detection and signatures.
- parsing
- RAR header parsing.
Structs§
- Chunk
MapEntry async - Mapping of a chunk within the logical file.
- Inner
File async - A file inside a RAR archive.
- Inner
File Stream async - Streaming reader for InnerFile ranges. Implements Stream for async iteration over chunks.
- Local
File Media - Local file implementation.
- Parse
Options async - Options for parsing RAR archives.
- RarFile
Chunk async - A byte range within a single FileMedia (RAR volume).
- RarFiles
Package async - Multi-volume RAR archive parser.
- Read
Interval - Interval for reading a byte range.
- Stream
Chunk Info async - Chunk info for streaming prioritization.
Traits§
- File
Media async - Abstract file source that can provide byte ranges asynchronously.