Question

I'd like to have the ability to unrar files within my C program. I'm looking for a library which should have the ability to open and extract RAR 3 archives. I have found it surprisingly difficult to obtain a reasonable one. I've come across unrarlib (http://unrarlib.org) which seemed promising until I found out it is so heavily outdated. Google was unable to give me anything else.

Any help would be much appreciated.

Was it helpful?

Solution

Try http://packages.ubuntu.com/raring/unrar-free - these are current. On the right-hand side of the page, there is a link to .orig.tar.gz - this has the source in it.

Note that rar is a commercial product, it is closed source, and has licensing restrictions relating to the technology. There may not be an off-the-shelf source code you can use.

OTHER TIPS

Links: libarchive and their github.

It may seem a little archaic at first, but it flows pretty well once you understand it. I've added an example program that's 95% a copy of their simple read example.

#include <stdio.h>
#include <archive.h>

int main() {

    struct archive_entry *ae;
    const char * filename = "test.rar";
    int r;
    size_t size;

    struct archive *a = archive_read_new();
    archive_read_support_compression_all(a);
    archive_read_support_format_rar(a);
    r = archive_read_open_filename(a, filename, 16384);
    if (r != ARCHIVE_OK) {
        /* ERROR */
    }   
    r = archive_read_next_header(a, &ae);
    if (r != ARCHIVE_OK) {
        /* ERROR */
    }   

    char buff[1000];
    int buffsize = sizeof(buff);

    for (;;) {
        size = archive_read_data(a, buff, buffsize);
        if (size < 0) {
            /* ERROR */
        }
        if (size == 0)
            break;
        write(1, buff, size);
    }

    archive_read_free(a);
}

libarchive is good, but it is not up-to-date per se (some features are missing, such as support for encrypted RARs).

I see that unrar-free was mentioned. Try the unar/lsar commands from The Unarchiver. It is feature complete and you get support for the older RAR formats as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top