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
The
BitArchiveReaderclass 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: strargument) even when called with abytes, notstr.Example:
raises
BitException: Failed to open the archive file: No such file or directorySo 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. toin_buffer, and create the instance withpybit7z.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