Skip to content

rar.py

ofrak_components.rar

RarArchive (GenericBinary, FilesystemRoot) dataclass

Filesystem stored in a RAR archive.

RarUnpacker (Unpacker)

Unpack RAR archives using the free unrar tool.

unpack(self, resource, config) async

Unpack the given resource.

Users should not call this method directly; rather, they should run Resource.run or Resource.unpack.

Parameters:

Name Type Description Default
resource Resource

The resource that is being unpacked

required
config ~CC

Optional config for unpacking. If an implementation provides a default, this default will always be used when config would otherwise be None. Note that a copy of the default config will be passed, so the default config values cannot be modified persistently by a component run.

required
Source code in ofrak_components/rar.py
async def unpack(self, resource: Resource, config: CC):
    with tempfile.NamedTemporaryFile(
        suffix=".rar"
    ) as temp_archive, tempfile.TemporaryDirectory() as temp_dir:
        temp_archive.write(await resource.get_data())
        temp_archive.flush()

        command = ["unar", "-no-directory", "-no-recursion", temp_archive.name]
        subprocess.run(command, cwd=temp_dir, check=True, capture_output=True)

        rar_view = await resource.view_as(RarArchive)
        await rar_view.initialize_from_disk(temp_dir)