-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add_file_from_memory() can't add binary files #68
Comments
Found this workaround:
with libarchive.file_writer('bytes.tar', 'pax') as ar:
content = b'bytes'
- ar.add_file_from_memory('bytes.bin', len(content), content)
+ ar.add_file_from_memory('bytes.bin', len(content), [content]) Or, why not do exactly the same inside the function to fix the problem (untested): --- a/libarchive/write.py
+++ b/libarchive/write.py
@@ -99,6 +99,10 @@ class ArchiveWrite(object):
entry_set_perm(archive_entry_pointer, permission)
write_header(archive_pointer, archive_entry_pointer)
+ # Make bytestrings work #68
+ if isinstance(entry_data, bytes):
+ entry_data = [entry_data]
+
for chunk in entry_data:
if not chunk:
break |
AFAICT your "workaround" is in fact the one and only correct way to use this method. |
I found out the hard way that if you feed a unicode string to entry_data (e.g., So, if This also pops up if you are using the But what caused me the most trouble is that, regardless of the import above... The more I think about it, the more I wonder if this is simply a bug. For Python3 at least, |
add_file_from_memory()
fails if given a bytestring of nonzero length (regardless of content):Of course, converting the bytestring to string as a workaround is not always an option.
A better testcase would include some actual invalid UTF-8 (like
b'\x80'
), to assert binary cleanliness, but as demonstrated, that was not the problem here.Python 3.6.4
python3-libarchive-c 2.7
The text was updated successfully, but these errors were encountered: