From c9f15fef8427e266df5a8be9b94c23a3c8e4be51 Mon Sep 17 00:00:00 2001 From: Jessica Hair Date: Wed, 18 Dec 2019 10:06:09 -0500 Subject: [PATCH] Check if data is already bytes --- libarchive/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libarchive/__init__.py b/libarchive/__init__.py index 8cd8f95..7fd44b6 100644 --- a/libarchive/__init__.py +++ b/libarchive/__init__.py @@ -550,7 +550,10 @@ class Archive(object): if data: if PY3: - result = _libarchive.archive_write_data_from_str(self._a, data.encode('utf8')) + if isinstance(data, bytes): + result = _libarchive.archive_write_data_from_str(self._a, data) + else: + result = _libarchive.archive_write_data_from_str(self._a, data.encode('utf8')) else: result = _libarchive.archive_write_data_from_str(self._a, data) _libarchive.archive_write_finish_entry(self._a)