diff options
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 8e9325b..41bf49a 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -1147,8 +1147,15 @@ class _ZipWriteFile(io.BufferedIOBase): def write(self, data): if self.closed: raise ValueError('I/O operation on closed file.') - nbytes = len(data) + + # Accept any data that supports the buffer protocol + if isinstance(data, (bytes, bytearray)): + nbytes = len(data) + else: + data = memoryview(data) + nbytes = data.nbytes self._file_size += nbytes + self._crc = crc32(data, self._crc) if self._compressor: data = self._compressor.compress(data) |