RAR Archive Format

In the digital age, where data is king and storage efficiency paramount, RAR archives have remained a steadfast and ubiquitous solution for compressing and organizing files.

About RAR Archive Information

The RAR archive format, short for ‘Roshal Archive’, is a widely used and well-regarded compression format designed to reduce the size of files and folders while preserving their integrity. Developed by Eugene Roshal, RAR is known for its high compression ratios and support for various compression methods.

RAR archive File Format History Info

RAR was created by Eugene Roshal in the early 1990s. It was initially introduced as a proprietary format with a focus on efficient compression and error recovery. Over the years, RAR gained popularity due to its exceptional compression capabilities and robust features. Although RAR was initially closed-source, it has since been partially opened, with decompression algorithms being made available to the public. Since 2013 version 5 of format became the default option. Compressing to legacy 4 version is still feasible by modern WinRAR.

Structure of RAR Archive

RAR archives are structured as collections of compressed files and folders. They typically consist of a series of blocks, each serving a specific purpose within the archive. These blocks include file data, headers, and optional recovery records, which can be used to repair damaged archives. Large archives can be split into smaller parts or merged back together. Self-extracting archives can be created as well.

RAR Compression Methods

RAR has only one compression algorithm. The format supports strong AES encryption for both content and filenames. WinRAR allows creating “solid” archives that provide better compression ratios by analyzing multiple files together. The obsolete version RAR4 optionally supports dedicated compression for text, audio and image data.

RAR Archive Supported Operations

Aspose.ZIP allows user extract either particular entry or whole archive. Creation and modification of RAR archive are not supported. Aspose.ZIP is able to extract modern RAR5 and legacy RAR4 versions of archive.

RAR-file - Internal Structure

RAR archives have a hierarchical internal structure comprising headers, compressed data, and optional recovery records. The structure allows for efficient extraction of specific files without decompressing the entire archive. If the archive is encrypted there it contains encryption header. Main header includes the optional locator to quickly access the positions of different service blocks without scanning the entire archive. Each entry has file and service header. Those headers contain file attributes and metadata, including checksum, system times, name and similar details.

RAR-file - Internal Structure

Popularity of RAR Archive and Support

RAR archives are widely used for compressing and sharing files due to their excellent compression ratios and versatility. They are popular in both the Windows and macOS ecosystems and enjoy strong support from various software tools. While RAR is not entirely open-source, numerous third-party applications and libraries provide support for creating, extracting, and managing RAR archives across different platforms.

Examples of Using RAR

Aspose.ZIP API lets extract archives in your applications without the need of any other 3rd party applications. Aspose.ZIP API provides RarArchive class to work with RAR archives. PI provides the RarArchiveEntryclass to represents a single file within the RAR archive.

Extract an RAR Entry

The following code example demonstrates how to extract an entry using RarArchive instance.

    using (RarArchive archive = new RarArchive("archive.rar"))
    {
        using (var destination = File.Create(dataDir + "firstEntry.txt"))
        {
                using (var source = archive.Entries[0].Open())
                {
                    byte[] buffer = new byte[1024];
                    int bytesRead;
                    while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)                       
                        destination.Write(buffer, 0, bytesRead);
                            
                }                    
        }
    }

Extract an Encrypted Entry

The following code example demonstrates how to extract an encrypted entry using RarArchive instance.

    FileInfo fi = new FileInfo("encrypted.rar");
    using (RarArchive archive = new RarArchive(fi.OpenRead()))
    {
        using (var destination = File.Create(dataDir + "firstEntry.txt"))
        {
            archive.Entries[0].Extract(destination, "p@s$w0rd");                
        }
    }

Extracting Compressed Directory

The following code example demonstrates how to all the files from RarArchive instance.

    using (RarArchive archive = new RarArchive("archive.rar"))
    {
        archive.ExtractToDirectory("extracted");
    }

Additional information about RAR-archives

People have been asking

1. Is RAR more efficient than ZIP?

Whether RAR is more efficient than ZIP depends on the specific use case and the type of data being compressed. Both RAR and ZIP are popular archive formats, but they have some differences in terms of compression efficiency, features, and compatibility.

2. How can I compose RAR archive?

The only tool allows composition is WinRAR. You will not find any other software piece or library because such is the RAR license .

3. Are all RAR files safe?

RAR files themselves are typically safe, as they are just archive containers that can hold various types of data, similar to ZIP files . However, the safety of a RAR file depends on the contents it holds and its source.