summaryrefslogtreecommitdiff
path: root/Lib/gzip.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 8b12225809..21d83e6414 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -334,17 +334,20 @@ class GzipFile(io.BufferedIOBase):
if self.fileobj is None:
raise ValueError("write() on closed GzipFile object")
- # Convert data type if called by io.BufferedWriter.
- if isinstance(data, memoryview):
- data = data.tobytes()
+ if isinstance(data, bytes):
+ length = len(data)
+ else:
+ # accept any data that supports the buffer protocol
+ data = memoryview(data)
+ length = data.nbytes
- if len(data) > 0:
+ if length > 0:
self.fileobj.write(self.compress.compress(data))
- self.size += len(data)
+ self.size += length
self.crc = zlib.crc32(data, self.crc) & 0xffffffff
- self.offset += len(data)
+ self.offset += length
- return len(data)
+ return length
def read(self, size=-1):
self._check_closed()