Can Unrar Extract Files from Piped Stdin?

This article examines whether the official unrar command-line utility can extract archive files directly from a piped standard input stream (stdin). The official RARLAB unrar utility does not natively support reading archive streams from standard input because RAR archive processing requires seeking capabilities that pipes cannot provide. Below is a breakdown of why this limitation exists, along with practical workarounds for extracting RAR data received from a pipe.

Why Unrar Cannot Read from Stdin

The official unrar utility relies on filesystem seek operations (fseek/lseek) to navigate headers, metadata blocks, and individual file records within a .rar file. When data is passed via standard input using a pipe (such as cat archive.rar | unrar x -), the input is treated as a unidirectional, non-seekable FIFO stream.

Because unrar cannot seek backward or jump forward arbitrarily within a live stream, it refuses to process input from stdin and expects a real, accessible file path.

Alternative 1: Pipe to Temporary Memory Storage

If your workflow requires handling a stream from a pipe (such as downloading a file via curl or receiving it from a remote shell), the most reliable method is to buffer the stream into a temporary file located in RAM using /dev/shm or mktemp.

curl -s "https://example.com/file.rar" | {
    temp_file=$(mktemp /dev/shm/archive.XXXXXX.rar)
    cat > "$temp_file"
    unrar x "$temp_file"
    rm -f "$temp_file"
}

Using /dev/shm ensures the data resides in shared memory rather than being written to physical disk storage, keeping performance fast while providing the seekable file descriptor that unrar requires.

Alternative 2: Using bsdtar (Libarchive)

The bsdtar utility, powered by libarchive, supports extracting certain formats from standard input using the - flag. It can extract older RAR formats (specifically RAR4 and earlier) directly from stdin:

cat archive.rar | bsdtar -xf -

This method will fail on modern RAR5 archives, as libarchive currently has limited or read-only support for newer RAR compression algorithms.

Alternative 3: 7-Zip (7z)

The 7-Zip command-line tool supports a -si flag to read standard input. However, because RAR decompression generally requires seeking, 7-Zip must buffer the entire stream into memory automatically:

cat archive.rar | 7z x -si -an

While this allows a direct pipe syntax, support varies depending on whether the archive is a single-part file and which version of the RAR format was used to create it.