From c94a053099031dd98f0447d5435335e30f1f0926 Mon Sep 17 00:00:00 2001 From: Vadim Lebedev Date: Mon, 8 Aug 2022 20:23:13 +0200 Subject: [PATCH] Unicode - related fixes --- libarchive/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libarchive/__init__.py b/libarchive/__init__.py index 4580b52..5823835 100644 --- a/libarchive/__init__.py +++ b/libarchive/__init__.py @@ -287,9 +287,9 @@ class EntryWriteStream(object): if PY3: self.buffer.write(data) else: - self.buffer.write(data.encode('utf-8')) + self.buffer.write(unicode(data, ENCODING)) else: - _libarchive.archive_write_data_from_str(self.archive._a, data.encode('utf-8')) + _libarchive.archive_write_data_from_str(self.archive._a, data.encode(ENCODING)) self.bytes += len(data) def close(self): @@ -298,7 +298,7 @@ class EntryWriteStream(object): if self.buffer: self.entry.size = self.buffer.tell() self.entry.to_archive(self.archive) - _libarchive.archive_write_data_from_str(self.archive._a, self.buffer.getvalue().encode('utf-8')) + _libarchive.archive_write_data_from_str(self.archive._a, self.buffer.getvalue().encode(ENCODING)) _libarchive.archive_write_finish_entry(self.archive._a) # Call archive.close() with _defer True to let it know we have been @@ -615,7 +615,7 @@ class Archive(object): 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')) + result = _libarchive.archive_write_data_from_str(self._a, data.encode(self.encoding)) else: result = _libarchive.archive_write_data_from_str(self._a, data) _libarchive.archive_write_finish_entry(self._a)