Skip to content
master
Go to file
Code

Files

Permalink
Failed to load latest commit information.

README.md

Build Status Download codecov

Junrar

Read and extracts from a .rar file. This is a fork of the junrar codebase, formerly on sourceforge.

Code may not be used to develop a RAR (WinRAR) compatible archiver.

Supported features

  • RAR 4 and lower (there is no RAR 5 support)
  • password protected archives (also with encrypted headers)
  • multi-part archives
  • extract from File and InputStream
  • extract to File and OutputStream

Installation

Gradle
implementation "com.github.junrar:junrar:{version}"
Gradle (Kotlin DSL)
implementation("com.github.junrar:junrar:{version}")
Maven
<dependency>
    <groupId>com.github.junrar</groupId>
    <artifactId>junrar</artifactId>
    <version>{version}</version>
</dependency>

where {version} corresponds to version as below:

  • Java 8 Version: Download
  • Java 6 Compatible Version: Download

Apache Commons VFS support has been removed from 5.0.0, and moved to a dedicated repo: https://github.com/junrar/commons-vfs-rar

Usage

Extract from a file to a directory:

Junrar.extract("/tmp/foo.rar", "/tmp");
//or
final File rar = new File("foo.rar");  
final File destinationFolder = new File("destinationFolder");
Junrar.extract(rar, destinationFolder);    
//or
final InputStream resourceAsStream = Foo.class.getResourceAsStream("foo.rar");//only for a single rar file
Junrar.extract(resourceAsStream, tempFolder);

Extract from an InputStream to an OutputStream

// Assuming you already have an InputStream from the rar file and an OutputStream for writing to
final Archive archive = new Archive(inputStream);
  while (true) {
      FileHeader fileHeader = archive.nextFileHeader();
      if (fileHeader == null) {
          break;
      }
      archive.extractFile(fileHeader, outputStream); 
  }

List files

final List<ContentDescription> contentDescriptions = Junrar.getContentsDescription(testDocuments);    

Extract a password protected archive

Junrar.extract("/tmp/foo.rar", "/tmp", "password");
//or
final File rar = new File("foo.rar");  
final File destinationFolder = new File("destinationFolder");
Junrar.extract(rar, destinationFolder, "password");    
//or
final InputStream resourceAsStream = Foo.class.getResourceAsStream("foo.rar");//only for a single rar file
Junrar.extract(resourceAsStream, tempFolder, "password");

Extract a multi-volume archive

Junrar.extract("/tmp/foo.001.rar", "/tmp");
You can’t perform that action at this time.