| 1161 | return True |
| 1162 | |
| 1163 | def write(self, data): |
| 1164 | if self.closed: |
| 1165 | raise ValueError('I/O operation on closed file.') |
| 1166 | |
| 1167 | # Accept any data that supports the buffer protocol |
| 1168 | if isinstance(data, (bytes, bytearray)): |
| 1169 | nbytes = len(data) |
| 1170 | else: |
| 1171 | data = memoryview(data) |
| 1172 | nbytes = data.nbytes |
| 1173 | self._file_size += nbytes |
| 1174 | |
| 1175 | self._crc = crc32(data, self._crc) |
| 1176 | if self._compressor: |
| 1177 | data = self._compressor.compress(data) |
| 1178 | self._compress_size += len(data) |
| 1179 | self._fileobj.write(data) |
| 1180 | return nbytes |
| 1181 | |
| 1182 | def close(self): |
| 1183 | if self.closed: |