Skip to main content

Read RAR file from python -- cffi edition

Project description

Build

unrar2-cffi -- Work with RAR files.

Description

unrar2-cffi is a python extension that exposes unrar library functionality through a zipfile-like interface.

This is a fork/modified version of unrar-cffi that supports modern Python starting from 3.9+

This build also target unrar 6.x instead of unrar 5.x from the original unrar-cffi project.

Difference

This packages has some difference to the original one:

  • Added typing information
  • Added __slots__ to improve performance a bit.
  • Moved all the RarInfo into at-property data
    • Now you can access the raw header data by using file._header
  • Added docstring to most functions.
  • Implement RarFile.printdir()

Features

The package implements the following RarFile functions:

  • namelist()
  • infolist()
  • getinfo()
  • read()
  • open()
  • testrar()
  • rarfile.is_rar_file()

Usage

  1. Install with PIP:

    pip install unrar2-cffi

  2. Use from code:

    from unrar.cffi import rarfile

    rar = rarfile.RarFile('sample.rar')

    assert rar.testrar() == None

    for filename in rar.namelist():
        info = rar.getinfo(filename)
        print("Reading {}, {}, {} bytes ({} bytes compressed)".format(info.filename, info.date_time, info.file_size, info.compress_size))
        data = rar.read(filename)
        print("\t{}...\n".format(data[:100]))

Build

Requirements

Linux/macOS:

  • gcc compiler suite (build-essential packages should be enough)
  • docker (only for buildmanylinux)

Windows:

  • VS2022 Build Tools (PLATFORM_TOOLSET=v143)
  • Visual C++ compiler suite
  • vswhere

Compile and test

  1. ./build.sh init
  2. ./build.sh build
  3. ./build.sh test

If you have docker installed, you can build all the manylinux wheels:

  1. ./build.sh within [manylinux docker image] buildmanylinux
  2. ./build.sh within [manylinux docker image] testmanylinux

By deafult the image quay.io/pypa/manylinux2010_x86_64 will be used. Use $DOCKER_IMAGE and $PLAT variables to customize the build.

Problems

Windows:

  • If you need to retarget solution, apply the 0001-build-retarget-to-vs2022-10.0-v143.patch that will utilize the latest version.

macOS:

  • The macOS version are monkeypatching unrar 6.x makefile to utilize C++11

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unrar2-cffi-0.3.1.tar.gz (262.7 kB view hashes)

Uploaded Source

Built Distributions

unrar2_cffi-0.3.1-cp312-cp312-win_amd64.whl (215.4 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

unrar2_cffi-0.3.1-cp312-cp312-win32.whl (184.2 kB view hashes)

Uploaded CPython 3.12 Windows x86

unrar2_cffi-0.3.1-cp312-cp312-musllinux_1_1_x86_64.whl (750.5 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

unrar2_cffi-0.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (201.0 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

unrar2_cffi-0.3.1-cp312-cp312-macosx_11_0_arm64.whl (158.9 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

unrar2_cffi-0.3.1-cp312-cp312-macosx_10_9_x86_64.whl (158.9 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

unrar2_cffi-0.3.1-cp311-cp311-win_amd64.whl (215.4 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

unrar2_cffi-0.3.1-cp311-cp311-win32.whl (184.1 kB view hashes)

Uploaded CPython 3.11 Windows x86

unrar2_cffi-0.3.1-cp311-cp311-musllinux_1_1_x86_64.whl (750.0 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

unrar2_cffi-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (200.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

unrar2_cffi-0.3.1-cp311-cp311-macosx_11_0_arm64.whl (158.9 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

unrar2_cffi-0.3.1-cp311-cp311-macosx_10_9_x86_64.whl (158.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

unrar2_cffi-0.3.1-cp310-cp310-win_amd64.whl (215.4 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

unrar2_cffi-0.3.1-cp310-cp310-win32.whl (184.1 kB view hashes)

Uploaded CPython 3.10 Windows x86

unrar2_cffi-0.3.1-cp310-cp310-musllinux_1_1_x86_64.whl (750.0 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

unrar2_cffi-0.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (200.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

unrar2_cffi-0.3.1-cp310-cp310-macosx_11_0_arm64.whl (158.9 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

unrar2_cffi-0.3.1-cp310-cp310-macosx_10_9_x86_64.whl (158.9 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

unrar2_cffi-0.3.1-cp39-cp39-win_amd64.whl (215.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

unrar2_cffi-0.3.1-cp39-cp39-win32.whl (184.1 kB view hashes)

Uploaded CPython 3.9 Windows x86

unrar2_cffi-0.3.1-cp39-cp39-musllinux_1_1_x86_64.whl (750.0 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

unrar2_cffi-0.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (200.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

unrar2_cffi-0.3.1-cp39-cp39-macosx_11_0_arm64.whl (158.9 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

unrar2_cffi-0.3.1-cp39-cp39-macosx_10_9_x86_64.whl (158.9 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page