Changaco / python-libarchive-c

Python interface to libarchive
Other
70 stars 37 forks source link

Enhance add_file_from_memory #85

Closed MartinFalatic closed 4 years ago

MartinFalatic commented 5 years ago

Closes #68, #69

MartinFalatic commented 5 years ago

Depending on which or #85 or #86 is merged first, the other will need to be rebased before merge.

Changaco commented 5 years ago

This branch doesn't really fix #68 and #69, it only clarifies the docstring of the add_file_from_memory method a little.

MartinFalatic commented 5 years ago

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).

Changaco commented 5 years ago

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.