Configure Unrar to Read from a Named Pipe

Extracting archives directly through a named pipe (FIFO) allows you to process compressed data on the fly without writing intermediate archive files to disk. While standard unrar operations expect seekable regular files on the filesystem, you can configure unrar to consume data from a named pipe by using stream-reading switches combined with standard Unix shell redirection. This guide demonstrates how to set up the pipe, pass data through it, and configure unrar to extract the incoming stream seamlessly.

Understanding the Non-Seekable Stream Limitation

By default, the RAR format uses headers and block structures that typically require the extraction tool to seek backwards and forwards across the file. A named pipe is a unidirectional FIFO buffer that does not support random seeking (issuing an lseek system call returns an ESPIPE error).

To overcome this, modern versions of unrar provide the -si (Standard Input) switch. This switch tells unrar to operate in streaming mode, reading sequential chunks without attempting to rewind the input source.

Step 1: Create the Named Pipe

Use the mkfifo utility to create a named pipe in your preferred directory:

mkfifo /tmp/rar_stream.fifo

Step 2: Feed Data into the Pipe

A named pipe blocks until processes are attached to both the writing end and the reading end. In a separate terminal or as a background process, send your archive data into the FIFO pipe:

cat /path/to/source_archive.rar > /tmp/rar_stream.fifo &

This source can be any command output, such as data downloaded via curl, decrypted using gpg, or piped from remote network storage.

Step 3: Run Unrar with Standard Input Redirection

To read from the named pipe, redirect the FIFO into unrar's standard input while specifying the -si flag.

Syntax:

unrar x -si[optional_name] [destination_directory/] < /path/to/named_pipe

Example:

To extract the contents directly into an output folder named extracted_data/:

mkdir -p extracted_data
unrar x -si extracted_data/ < /tmp/rar_stream.fifo

If you do not specify a destination path, unrar will extract the contents into the current working directory.

Passing the Named Pipe Directly

Some modern builds of unrar allow passing the named pipe directly as the file argument, provided that the archive was created without features requiring seeking:

unrar x /tmp/rar_stream.fifo extracted_data/

However, redirecting the pipe through stdin using unrar x -si < /tmp/rar_stream.fifo remains the most reliable method, as it explicitly triggers internal sequential-read buffers.

Constraints and Considerations

  • Solid Archives: Archives created with the "solid" compression flag (-s) enforce sequential extraction by default, making them generally compatible with streaming. However, extracting single specific files from a solid stream requires processing all preceding data in the stream.
  • Corrupted or Reversed Blocks: If an archive structure contains central directories placed exclusively at the end of the file, sequential stream extraction may fail or require significant memory buffering.
  • Multi-Volume Archives: Reading multi-volume RAR files (.part1.rar, .part2.rar) through a single named pipe is not natively supported in sequential mode, as unrar requires distinct file boundary handles to cycle between volumes.