| 270 | self.fileobj.write(fname + b'\000') |
| 271 | |
| 272 | def write(self,data): |
| 273 | self._check_not_closed() |
| 274 | if self.mode != WRITE: |
| 275 | import errno |
| 276 | raise OSError(errno.EBADF, "write() on read-only GzipFile object") |
| 277 | |
| 278 | if self.fileobj is None: |
| 279 | raise ValueError("write() on closed GzipFile object") |
| 280 | |
| 281 | if isinstance(data, (bytes, bytearray)): |
| 282 | length = len(data) |
| 283 | else: |
| 284 | # accept any data that supports the buffer protocol |
| 285 | data = memoryview(data) |
| 286 | length = data.nbytes |
| 287 | |
| 288 | if length > 0: |
| 289 | self.fileobj.write(self.compress.compress(data)) |
| 290 | self.size += length |
| 291 | self.crc = zlib.crc32(data, self.crc) |
| 292 | self.offset += length |
| 293 | |
| 294 | return length |
| 295 | |
| 296 | def read(self, size=-1): |
| 297 | self._check_not_closed() |