Closed MartinFalatic closed 4 years ago
Depending on which or #85 or #86 is merged first, the other will need to be rebased before merge.
This branch doesn't really fix #68 and #69, it only clarifies the docstring of the add_file_from_memory
method a little.
Those issues are both a failure of information and example. As the only examples provided are in the form of tests and the minimalist docstrings, I enhanced both to better specify exactly what the parameters must be in order for the process to succeed.
The test, in particular, was designed to show the best practice for various inputs is to encode them as binary if they aren't already.
I originally had a test that included a non-binary string, thus the "unnecessary code" you removed. In fact, that was to be yet another example of how to correctly handle non-binary string inputs, but it seems better served by the commentary within the test stating that non-binary inputs will cause unwelcome results.
Correct documentation would have prevented both issues, so yes, this fixes that gap. The only thing that would work better is explicitly disallowing any non-binary input, but that might break some applications of it (applications that would break the moment they use Python 3 and default unicode strings - that's how I first learned that, other than unaddressed bug reports, this was undocumented).
It's not just a documentation issue. We can make the add_file_from_memory
method more friendly by modifying it to accept a single bytestring as well as a list of bytestrings, as proposed in https://github.com/Changaco/python-libarchive-c/issues/68#issuecomment-385109824.
I don't want to close #69 until I see a non-failing test proving that NUL characters are in fact handled correctly.
Closes #68, #69