Skip to content

BitArchiveReader with input from a memory buffer issue #114

@bzaborow

Description

@bzaborow

The BitArchiveReader class uses overloaded constructor - for 2 versions, a file-input version and memory-buffer-input version.
Unfortunately it appears to me that there is no way to create an instance of memory buffer version. Overloading resolution in pybind gets fooled here somehow and runs the file version (with in_archive: str argument) even when called with a bytes, not str.

Example:

import pybit7z
with open("example.7z", "rb") as fin:
    my_buffer = fin.read()
with pybit7z.lib7zip_context() as lib:
    arc = pybit7z.BitArchiveReader(lib, my_buffer)

raises
BitException: Failed to open the archive file: No such file or directory

So far I tried to explicitly disable conversion of this argument with py::arg("in_archive").noconvert(), unfortunately without luck. The simplest workaround I've got is to rename the argument in one of the versions in binding, e.g. to in_buffer, and create the instance with pybit7z.BitArchiveReader(lib, in_buffer=my_byffer). Other option would be to rename the class (or both, to be consistent with other classes, like BitMemExtractor vs BitFileExtractor and so on).

I'm not an expert on pybind, so there may be a better solution.

I attached a patch for the workaround using renamed argument, for a reference.
pybit7z-BitArchiveReader-memory-buffer.patch

Best,
Bartosz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions