go-unarr

repository·master·Indexed 43 days ago

https://github.com/gen2brain/go-unarr

Go bindings for the unarr library providing decompression for RAR, TAR, ZIP, and 7z archives. Includes a programmatic Go library and a command-line interface for extracting archive contents.

Tokens
3.9K
Snippets
24
Records
29
Agent score
55%

What's inside go-unarr

  1. Overview of (lib)unarr

    master
    (lib)unarr is a decompression library designed for extracting RAR, TAR, ZIP, and 7z* archives. It was originally forked from unarr to provide a CMake-based build system and ongoing maintenance for the unmaintained original project. It is particularly useful for handling archives that require specific filter or solid compression support.
  2. Understand (lib)unarr limitations and 7z support

    master

    Limitations

    (lib)unarr does not currently support:

    • Password protected archives
    • Self-extracting archives
    • Split archives

    7z Support

    7z support is limited and must be explicitly enabled at build time using -DENABLE_7Z=ON. This limitation exists due to a performance issue in the ANSI-C based 7z extraction code provided by the LZMA SDK when handling large files with solid compression.

  3. Configure an embedded build of (lib)unarr

    master

    For an embedded build, copy the source code directly into your project and ensure your compiler is C99 compatible. To enable support for specific compression formats using third-party libraries, define the following symbols and ensure the corresponding headers are in your include path:

    | Symbol            | Required header | Required for (format/method)|
    |-------------------|:---------------:|----------------------------|
    |HAVE_ZLIB          |     zlib.h      |  faster CRC-32 and Deflate  |
    |HAVE_BZIP2         |     bzlib.h     |    ZIP / Bzip2              |
    |HAVE_LIBLZMA       |     lzma.h      |    ZIP / LZMA, XZ(LZMA2)    |
    |HAVE_7Z            |     7z.h        |    7Z / LZMA, LZMA2, BCJ    |
    |_7ZIP_PPMD_SUPPPORT|                 |    7Z / PPMd                |
  4. Build (lib)unarr from source using CMake

    master

    To build (lib)unarr from source, use CMake. You can configure the build to produce a static library or enable 7z support. By default, the build system attempts to detect and use system libraries like bzip2, xz/LibLZMA, and zlib. You can explicitly disable system library detection if you prefer to use embedded versions.

    # Standard build
    mkdir build
    cd build
    cmake ..
    make
    
    # Build as a static library
    cmake .. -DBUILD_SHARED_LIBS=OFF
    
    # Build with 7z support enabled
    cmake .. -DENABLE_7Z=ON
    
    # Disable system library detection (to use embedded versions)
    cmake .. -DUSE_SYSTEM_BZ2=OFF -DUSE_SYSTEM_LZMA=OFF -DUSE_SYSTEM_ZLIB=OFF
    
    # Install the library
    make install
  5. Install the unarr CLI

    master

    You can install the unarr command-line tool directly using go install. This tool provides decompression capabilities for RAR, TAR, ZIP, and 7z archives.

    go install github.com/gen2brain/go-unarr/cmd/unarr@latest
  6. Overview of zlib compression library

    master

    zlib is a general-purpose data compression library. It is thread-safe and implements data formats described by RFCs 1950 (zlib format), 1951 (deflate format), and 1952 (gzip format).

    Key resources for developers:

    • API Documentation: All functions are documented in zlib.h.
    • Usage Examples: See test/example.c for a general usage example and test/minigzip.c for a minigzip implementation.
    • ZIP Support: An experimental package for reading and writing .zip files built on top of zlib is available in the contrib/minizip directory.
  7. Build bzip2 shared library (libbz2.so) on UNIX

    master

    To build the shared library libbz2.so and the bzip2-shared client, use the specific Makefile for shared libraries. Note that building shared objects on x86 platforms may result in a 10%-20% performance slowdown because it makes the %ebx register unavailable to gcc.

    Important Migration Note: If upgrading from version 0.9.0/0.9.5 to 1.0.X, all library functions have been renamed to avoid namespace pollution (e.g., bzCompress is now BZ2_bzCompress). Consequently, shared libraries created with the 1.0.X Makefile are not compatible with programs written for older versions.

    make -f Makefile-libbz2_so
  8. Build bzip2/libbzip2 on UNIX (Static Library)

    master

    To build the static library libbz2.a and the programs bzip2 and bzip2recover, run make. This process includes six self-tests. If the tests pass, you can install the components.

    To install to default system paths (/usr/local/bin, /usr/local/lib, etc.), use: make install

    To install to a custom directory, use the PREFIX variable: make install PREFIX=/xxx/yyy

    To preview the installation commands without executing them, use the -n flag:

    # Build and run self-tests
    make
    
    # Install to default locations
    make install
    
    # Install to a custom prefix
    make install PREFIX=/xxx/yyy
    
    # Dry run to see commands before executing
    make -n install PREFIX=/xxx/yyy
  9. Install and build zlib

    master

    To compile the zlib library and run the included test programs on most Unix-like systems, use the following sequence:

    1. Run the configuration script: ./configure
    2. Build and run tests: make test
    3. Install the library: make install

    Platform Specifics:

    • Windows: Use the special makefiles located in win32/ or contrib/vstudio/.
    • VMS: Use make_vms.com.
    • 64-bit Irix: deflate.c must be compiled without optimization (avoid -O) to prevent test failures due to compiler bugs.
    ./configure
    make test
    make install